SQL SERVER比COUNT(*)快得多,JOINS DB包含超过3000万行,包含30列

时间:2017-11-10 12:22:43

标签: sql sql-server sql-server-2014

   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

伯爵的执行计划:

https://www.brentozar.com/pastetheplan/?id=rkkKfxO1M

0 个答案:

没有答案