我想查看簡單的選擇頂部(n)的查詢計劃。每當我改變n(我得到的記錄數)時,查詢計劃會發生變化,Select Top 10特別會導致性能問題,如果查詢計數少於10或大於10,查詢將順利運行。不同的SQL查詢計劃與選擇頂部(n)
查詢由實體框架(4.2)生成,如果它有所作爲。
查詢是:
exec sp_executesql N'SELECT TOP (10)
[Project1].[Id] AS [Id],
[Project1].[DateReceived] AS [DateReceived],
[Project1].[Status] AS [Status],
[Project1].[Subject] AS [Subject],
[Project1].[Description] AS [Description],
[Project1].[Path] AS [Path],
[Project1].[C1] AS [C1],
[Project1].[C2] AS [C2],
[Project1].[C3] AS [C3],
.
.
.
.
.
.
.
WHERE [Project1].[row_number] > 0
ORDER BY [Project1].[DateReceived] DESC',N'@p__linq__0 int,@p__linq__1 int,@p__linq__2 datetime2(7),@p__linq__3 datetime2(7),@p__linq__4 nvarchar(4000),@p__linq__5 nvarchar(4000),@p__linq__6 nvarchar(4000),@p__linq__7 nvarchar(4000)',@p__linq__0=-1,@p__linq__1=-1,@p__linq__2='2013-03-15 00:00:00',@p__linq__3='2013-04-15 23:59:55',@p__linq__4=N'ALL',@p__linq__5=N'ALL',@p__linq__6=N'',@p__linq__7=N'%%'
爲什麼TOP 10特別是導致性能問題?
我不能分享圖片的是,這裏是鏈接:
http://imageshack.us/photo/my-images/407/top10a.png/
http://imageshack.us/photo/my-images/580/top20x.png/
什麼是你的**問題**? – Luv
你可以發佈執行計劃嗎?這將是非常有幫助的。 我的第一個想法: SQL Server使用它的統計信息更改它的執行計劃。你可以假設更新統計。 –
執行計劃添加到我的問題上面。 –