Ich habe die folgende Abfrage, die < 1s nimmt, wenn ORDER BY b.Price
verwendet wird, und 10s über, wenn ORDER BY b.Price DESC
verwendet wirdORDER BY indexierte Spalte ist immer noch langsam
select * from
(
select
/* When changed to ORDER BY b.Price DESC it's 10x slower! */
(row_number() over (ORDER BY b.Price)) as RowNumber,
b.*
from
Books b (nolock)
inner join BookPublishRegions p (nolock)
on b.BookKey = bp.BookKey
where
contains(p.PublishRegionName, 'France')
) as t1
where t1.RowNumber between 100 and 110
Irgendwelche Gedanken auf, warum?
Ich habe sowohl einen aufsteigenden und absteigenden Index auf b.Price
. Ich bin nicht wirklich sicher, was sonst kann ich hier tun ...
Als Referenz ich bin auch das Skript für beiden Indizes CREATE unten:
CREATE NONCLUSTERED INDEX [IX_Books_PriceDesc] ON [dbo].[Books]
(
[Price] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX [IX_Books_Price] ON [dbo].[Books]
(
[Price] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Zeigen Sie uns die Indizes –
Sie wahrscheinlich den Index auf Preis asc Änderung es DESC https://technet.microsoft.com/en-us/library/ms181154%28v=sql.105%29.aspx – Mihai
Vielleicht haben Sie könnte uns eine EXPLAIN zeigen? –