У меня есть таблица с именем BPIrequests
с 28M строками, которую я использую Entity Framework для запроса по диапазону дат.Это запрос, который он выдает, что время ожидания:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Request ID] AS [Request ID],
[Extent1].[Date] AS [Date],
[Extent1].[Lumen URL] AS [Lumen URL],
[Extent1].[Copyright owner ID] AS [Copyright owner ID],
[Extent1].[Copyright owner name] AS [Copyright owner name],
[Extent1].[Reporting organization ID] AS [Reporting organization ID],
[Extent1].[Reporting organization name] AS [Reporting organization name],
[Extent1].[URLs removed] AS [URLs removed],
[Extent1].[URLs that were not in Google's search index] AS [URLs that were not in Google's search index],
[Extent1].[URLs for which we took no action] AS [URLs for which we took no action],
[Extent1].[URLs pending review] AS [URLs pending review],
[Extent1].[From Abuser] AS [From Abuser]
FROM
[dbo].[BPIrequests] AS [Extent1]
WHERE
((convert (datetime2, convert(varchar(255), [Extent1].[Date], 102) , 102)) >= (convert (datetime2, convert(varchar(255), convert(datetime2, '2019-01-11 19:44:10.0000000', 121), 102) , 102)))
AND ((convert (datetime2, convert(varchar(255), [Extent1].[Date], 102) , 102)) <= (convert (datetime2, convert(varchar(255), convert(datetime2, '2019-01-26 19:44:10.8392197', 121), 102) , 102)))
Если я отредактирую запрос в SSMS, чтобы он выглядел так, он выполняется мгновенно:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Request ID] AS [Request ID],
[Extent1].[Date] AS [Date],
[Extent1].[Lumen URL] AS [Lumen URL],
[Extent1].[Copyright owner ID] AS [Copyright owner ID],
[Extent1].[Copyright owner name] AS [Copyright owner name],
[Extent1].[Reporting organization ID] AS [Reporting organization ID],
[Extent1].[Reporting organization name] AS [Reporting organization name],
[Extent1].[URLs removed] AS [URLs removed],
[Extent1].[URLs that were not in Google's search index] AS [URLs that were not in Google's search index],
[Extent1].[URLs for which we took no action] AS [URLs for which we took no action],
[Extent1].[URLs pending review] AS [URLs pending review],
[Extent1].[From Abuser] AS [From Abuser]
FROM
[dbo].[BPIrequests] AS [Extent1]
WHERE
[Extent1].[Date] >= '2019-01-11'
AND [Extent1].[Date] <= '2019-01-26'
вот планы запроса для сравнения:

Как мне заставить Entity Framework использовать индекс даты?