SELECT COUNT(*) FROM my_Table
当我们使用30列搜索超过3000万行
时,系统会变慢所以我们与sys.partitions,sys.tables
进行了交互查询:
SELECT SUM(p.rows) FROM sys.partitions AS p
INNER JOIN sys.tables AS t
ON p.[object_id] = t.[object_id]
INNER JOIN sys.schemas AS s
ON s.[schema_id] = t.[schema_id]
WHERE t.name = N'myTable'
AND s.name = N'dbo'
AND p.index_id IN (0,1);
但是我们想要它来加入。请建议
搜索查询的执行计划:
https://www.brentozar.com/pastetheplan/?id=HyzzW-Oyf
伯爵的执行计划: