I have the following query:
SELECT MAX([LastModifiedTime]) FROM Workflow
The Workflow table has approximately 400M rows. The LastModifiedTime column has an index:
CREATE NONCLUSTERED INDEX [IX_Workflow_LastModifiedTime] ON [dbo].[Workflow]
(
[LastModifiedTime] 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, FILLFACTOR = 100)
The above request takes 1.5 minutes. Why didn't SQL Server use the index above and just retrieve the last row in the index to get the maximum value?
BTW, the query plan for this query is displayed index scanat the index above.
Thank.
source
share