{"id":269120,"date":"2015-11-26T20:02:02","date_gmt":"2015-11-26T17:02:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=269120"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=269120","title":{"rendered":"\u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e COUNT(*)"},"content":{"rendered":"<p>       \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043b\u044e\u0431\u043b\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435? \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a\u0443.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e\u2026 \u042d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u043c-\u0442\u043e \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430?<\/p>\n<pre><code class=\"sql\">SELECT COUNT(*) FROM Sales.SalesOrderDetail SELECT COUNT_BIG(*) FROM Sales.SalesOrderDetail <\/code><\/pre>\n<p><a name=\"habracut\"><\/a> <br \/>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u043b\u0438: \u00ab\u041d\u0435\u0442\u00bb. \u0420\u0435\u0436\u0435 \u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u0434\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442: \u00ab\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0435\u0440\u043d\u0443\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u043e <i>COUNT<\/i> \u0432\u0435\u0440\u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <i>INT<\/i>, \u0430 <i>COUNT_BIG<\/i> \u2013 \u0442\u0438\u043f <i>BIGINT<\/i>\u00bb.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043d\u043e\u0433\u0438\u0435 \u0443\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0438\u0437 \u0432\u0438\u0434\u0430. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <i>COUNT<\/i> \u043d\u0430 \u043f\u043b\u0430\u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <i>Compute Scalar<\/i>:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/dc9\/064\/235\/dc90642352b04a6f9c46032aa8597816.png\"\/><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u0442\u043e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0442\u0430\u043c:<\/p>\n<pre><code class=\"sql\">[Expr1003] = Scalar Operator(CONVERT_IMPLICIT(int,[Expr1004],0)) <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <i>COUNT<\/i> \u043d\u0435\u044f\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <i>COUNT_BIG<\/i> \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442\u0441\u044f \u0432 <i>INT<\/i>. \u041d\u0435 \u0441\u043a\u0430\u0437\u0430\u043b \u0431\u044b, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440. \u041c\u043d\u043e\u0433\u0438\u0435, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0433\u0443\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0444\u0430\u043a\u0442 \u2013 <i>SQL Server<\/i> \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u043d\u0435\u0434\u043e\u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442 <i>Compute Scalar<\/i> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b. <\/p>\n<p>  \u0415\u0449\u0435 \u044f \u0437\u043d\u0430\u044e \u043b\u044e\u0434\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0431\u044f\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <i>SUM<\/i> \u0432\u043c\u0435\u0441\u0442\u043e <i>COUNT<\/i>:<\/p>\n<pre><code class=\"sql\">SELECT SUM(1) FROM Sales.SalesOrderDetail <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0432\u043d\u043e\u0437\u043d\u0430\u0447\u0435\u043d <i>COUNT<\/i>. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043b\u0438\u0448\u043d\u0438\u0439 <i>Compute Scalar<\/i> \u043d\u0430 \u043f\u043b\u0430\u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">[Expr1003] = Scalar Operator(CASE WHEN [Expr1004]=(0) THEN NULL ELSE [Expr1005] END) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u0440\u043e\u043d\u0435\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.\u2026<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u0448\u0435, \u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 <i>SQL Server<\/i> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <i>Full Index Scan<\/i> (\u0438\u043b\u0438 <i>Full Table Scan<\/i> \u0435\u0441\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0443\u0447\u0435\u0439). \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u044d\u0442\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0435 \u0431\u044b\u0441\u0442\u0440\u044b\u0435. \u041b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f: <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms187737%28v=sql.110%29.aspx\">sys.dm_db_partition_stats<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms175012%28v=sql.110%29.aspx\">sys.partitions<\/a> (\u0435\u0441\u0442\u044c \u0435\u0449\u0435 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/ms190283.aspx\">sysindexes<\/a>, \u043d\u043e \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 <i>SQL Server 2000<\/i>). <\/p>\n<pre><code class=\"sql\">USE AdventureWorks2012 GO  SET STATISTICS IO ON SET STATISTICS TIME ON GO  SELECT COUNT_BIG(*) FROM Sales.SalesOrderDetail  SELECT SUM(p.[rows]) FROM sys.partitions p WHERE p.[object_id] = OBJECT_ID('Sales.SalesOrderDetail')     AND p.index_id &lt; 2  SELECT SUM(s.row_count) FROM sys.dm_db_partition_stats s WHERE s.[object_id] = OBJECT_ID('Sales.SalesOrderDetail')     AND s.index_id &lt; 2 <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043f\u043b\u0430\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c \u043c\u0435\u043d\u0435\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u043d\u044b\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/48b\/f6f\/56d\/48bf6f56d5a248b587a58e465c70df74.png\"\/><\/p>\n<p>  \u041d\u0430 <i>AdventureWorks<\/i> \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u044f\u0432\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"sql\">Table 'SalesOrderDetail'. Scan count 1, logical reads 276, ...  SQL Server Execution Times:    CPU time = 12 ms,  elapsed time = 26 ms.  Table 'sysrowsets'. Scan count 1, logical reads 5, ...  SQL Server Execution Times:    CPU time = 4 ms,  elapsed time = 4 ms.  Table 'sysidxstats'. Scan count 1, logical reads 2, ...  SQL Server Execution Times:    CPU time = 2 ms,  elapsed time = 1 ms. <\/code><\/pre>\n<p>  \u0412\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441 30 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439:<\/p>\n<pre><code class=\"sql\">Table 'big_test'. Scan count 6, logical reads 114911, ...  SQL Server Execution Times:    CPU time = 4859 ms,  elapsed time = 5079 ms.  Table 'sysrowsets'. Scan count 1, logical reads 25, ...  SQL Server Execution Times:    CPU time = 0 ms,  elapsed time = 2 ms.  Table 'sysidxstats'. Scan count 1, logical reads 2, ...  SQL Server Execution Times:    CPU time = 0 ms,  elapsed time = 2 ms. <\/code><\/pre>\n<p>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u043a \u0431\u044b\u043b\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435 \u043d\u0435 \u0434\u0430\u0441\u0442 \u043e\u0441\u043e\u0431\u044b\u0445 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u2026<\/p>\n<pre><code class=\"sql\">IF EXISTS(SELECT * FROM Sales.SalesOrderDetail)     PRINT 1  IF EXISTS(     SELECT * FROM sys.dm_db_partition_stats     WHERE [object_id] = OBJECT_ID('Sales.SalesOrderDetail')         AND row_count &gt; 0 ) PRINT 1 <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"sql\">Table 'SalesOrderDetail'. Scan count 1, logical reads 2,...  SQL Server Execution Times:    CPU time = 1 ms,  elapsed time = 3 ms.  Table 'sysidxstats'. Scan count 1, logical reads 2,...  SQL Server Execution Times:    CPU time = 4 ms,  elapsed time = 5 ms. <\/code><\/pre>\n<p>  \u0418 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0436\u0435 \u043a\u0430\u043f\u0435\u043b\u044c\u043a\u0443 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <i>SQL Server<\/i> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438\u0437 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/452\/8f3\/1cd\/4528f31cdaee4231af1f8a1c4c7cf3d5.png\"\/><\/p>\n<p>  \u0415\u0449\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c \u0441\u0440\u0430\u0437\u0443. \u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0431\u0449\u0438\u0442\u044c.<\/p>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 #1 \u0441 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u043d\u0435\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u0443\u0440\u0441\u043e\u0440\u043e\u043c \u043e\u0431\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b:<\/p>\n<pre><code class=\"sql\">IF OBJECT_ID('tempdb.dbo.#temp') IS NOT NULL     DROP TABLE #temp GO CREATE TABLE #temp (obj SYSNAME, row_count BIGINT) GO  EXEC sys.sp_MSForEachTable @command1 = 'INSERT #temp SELECT ''?'', COUNT_BIG(*) FROM ?'  SELECT * FROM #temp ORDER BY row_count DESC <\/code><\/pre>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 #2 \u2013 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 SQL \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b <i>SELECT COUNT(*)<\/i>:<\/p>\n<pre><code class=\"sql\">DECLARE @SQL NVARCHAR(MAX)  SELECT @SQL = STUFF((     SELECT 'UNION ALL SELECT ''' + SCHEMA_NAME(o.[schema_id]) + '.' + o.name + ''', COUNT_BIG(*)     FROM [' + SCHEMA_NAME(o.[schema_id]) + '].[' + o.name + ']'     FROM sys.objects o     WHERE o.[type] = 'U'         AND o.is_ms_shipped = 0     FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 10, '') + ' ORDER BY 2 DESC'  PRINT @SQL EXEC sys.sp_executesql @SQL <\/code><\/pre>\n<p>  \u0412\u0430\u0440\u0438\u0430\u043d\u0442 #3 \u2013 \u0431\u044b\u0441\u0442\u0440\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c:<\/p>\n<pre><code class=\"sql\">SELECT SCHEMA_NAME(o.[schema_id]), o.name, t.row_count FROM sys.objects o JOIN (     SELECT p.[object_id], row_count = SUM(p.row_count)     FROM sys.dm_db_partition_stats p     WHERE p.index_id &lt; 2     GROUP BY p.[object_id] ) t ON t.[object_id] = o.[object_id] WHERE o.[type] = 'U'     AND o.is_ms_shipped = 0 ORDER BY t.row_count DESC <\/code><\/pre>\n<p>  \u0423\u0436 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u044f \u0432\u044b\u0434\u0430\u043b \u0434\u0438\u0444\u0438\u0440\u0430\u043c\u0431\u043e\u0432, \u0447\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0435 \u0445\u043e\u0440\u043e\u0448\u0438\u0435. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0438\u043c\u0438 \u043d\u0430\u0441 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u0434\u0441\u0442\u0435\u0440\u0435\u0433\u0430\u0442\u044c \u00ab\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0435\u00bb \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041f\u043e\u043c\u043d\u0438\u0442\u0441\u044f, \u0431\u044b\u043b \u0442\u0430\u043a\u043e\u0439 \u0432\u0435\u0441\u0435\u043b\u044b\u0439 \u0431\u0430\u0433, \u043a\u043e\u0433\u0434\u0430 \u043f\u0440\u0438 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0441 <i>SQL Server 2000<\/i> \u043d\u0430 <i>2005<\/i> \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u043b\u0438\u0441\u044c. \u041e\u0441\u043e\u0431\u043e \u0432\u0435\u0437\u0443\u0447\u0438\u043c \u043b\u044e\u0434\u044f\u043c, \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0438\u0437 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438\u0441\u044c \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445. \u041b\u0435\u0447\u0438\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <a href=\"https:\/\/msdn.microsoft.com\/ru-ru\/library\/ms188414%28v=sql.110%29.aspx\">DBCC UPDATEUSAGE<\/a>.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 <i>SQL Server 2005 SP1<\/i> \u044d\u0442\u043e\u0442 \u0431\u0430\u0433 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438 \u0438 \u0432\u0441\u0435 \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e\u2026 \u041d\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u043b \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0434, \u043a\u043e\u0433\u0434\u0430 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b \u0431\u0435\u043a\u0430\u043f \u0441 <i>SQL Server 2005 SP4<\/i> \u043d\u0430 <i>SQL Server 2012 SP2<\/i>. \u0412\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 \u0443\u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0433\u0443, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043c\u0430\u043d\u0443\u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"sql\">UPDATE STATISTICS Person.Person WITH ROWCOUNT = 1000000000000000000 <\/code><\/pre>\n<p>  \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>  \u0421\u0430\u043c\u044b\u0439 \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430\u0447\u0430\u043b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u043e\u043b\u044c\u0448\u0435 \u0447\u0435\u043c \u043e\u0431\u044b\u0447\u043d\u043e:<\/p>\n<pre><code class=\"sql\">SELECT FirstName, COUNT(*) FROM Person.Person GROUP BY FirstName <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b \u043d\u0430 \u043f\u043b\u0430\u043d \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u0443\u0432\u0438\u0434\u0435\u043b \u0442\u0430\u043c \u044f\u0432\u043d\u043e \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <i>Estimated number of rows<\/i>:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/57e\/6df\/b17\/57e6dfb179004d72b495940f59fa2491.png\"\/><\/p>\n<p>  \u0417\u0430\u0433\u043b\u044f\u043d\u0443\u043b \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441\u0443:<\/p>\n<pre><code class=\"sql\">DECLARE @SQL NVARCHAR(MAX) DECLARE @obj SYSNAME = 'Person.Person' SELECT @SQL = 'DBCC SHOW_STATISTICS(''' + @obj + ''', ' + name + ') WITH STAT_HEADER' FROM sys.stats WHERE [object_id] = OBJECT_ID(@obj)     AND stats_id &lt; 2  EXEC sys.sp_executesql @SQL <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0431\u044b\u043b\u043e \u0432 \u043d\u043e\u0440\u043c\u0435:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/838\/22b\/ef4\/83822bef4de54f76baf018b1ba19deb6.png\"\/><\/p>\n<p>  \u041d\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435:<\/p>\n<pre><code class=\"sql\">SELECT rowcnt FROM sys.sysindexes WHERE id = OBJECT_ID('Person.Person')     AND indid &lt; 2  SELECT SUM([rows]) FROM sys.partitions p WHERE p.[object_id] = OBJECT_ID('Person.Person')     AND p.index_id &lt; 2 <\/code><\/pre>\n<p>  \u0431\u044b\u043b\u0430 \u043f\u0435\u0447\u0430\u043b\u044c:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/64a\/1b9\/9d6\/64a1b99d65f64fd79c40325026449463.png\"\/><\/p>\n<p>  \u0412 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0432\u044b\u0431\u0440\u0430\u043b <i>Full Index Scan<\/i>. \u041f\u0440\u0438 <i>Full Index\/Table Scan<\/i> \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043d\u0435 \u0431\u0435\u0440\u0435\u0442 \u0438\u0437 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u0430 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u043c (\u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d \u0432\u0441\u0435\u0433\u0434\u0430 \u043b\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442).<\/p>\n<p>  \u041d\u0435 \u0441\u0435\u043a\u0440\u0435\u0442, \u0447\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <i>Estimated number of rows<\/i> <i>SQL Server<\/i> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c. \u0415\u0441\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u0439, \u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435.<\/p>\n<pre><code class=\"sql\">SELECT session_id, query_cost, requested_memory_kb, granted_memory_kb, required_memory_kb, used_memory_kb FROM sys.dm_exec_query_memory_grants <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043a \u0447\u0435\u043c\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"sql\">session_id query_cost       requested_memory_kb  granted_memory_kb    required_memory_kb   used_memory_kb ---------- ---------------- -------------------- -------------------- -------------------- -------------------- 56         11331568390567   769552               769552               6504                 6026 <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0438\u043b\u0430\u0441\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"sql\">DBCC UPDATEUSAGE(AdventureWorks2012, 'Person.Person') WITH COUNT_ROWS DBCC FREEPROCCACHE <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0432\u0441\u0435 \u043f\u0440\u0438\u0448\u043b\u043e \u0432 \u043d\u043e\u0440\u043c\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/dbc\/a99\/471\/dbca994716a24cfb802f472ab5fc16ae.png\"\/><\/p>\n<pre><code class=\"sql\">session_id query_cost          requested_memory_kb  granted_memory_kb    required_memory_kb   used_memory_kb ---------- ------------------- -------------------- -------------------- -------------------- -------------------- 52         0,291925808638711   1168                 1168                 1024                 952 <\/code><\/pre>\n<p>  \u0421\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u00ab\u0441\u043f\u0430\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043f\u0430\u043b\u043e\u0447\u043a\u043e\u0439\u00bb, \u0442\u043e \u043a\u0430\u043a\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f? \u041c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e-\u0441\u0442\u0430\u0440\u0438\u043d\u043a\u0435:<\/p>\n<pre><code class=\"sql\">SELECT COUNT_BIG(*) FROM ... <\/code><\/pre>\n<p>  \u041d\u043e \u043f\u0440\u0438 \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u044f \u0431\u044b \u043d\u0435 \u0434\u043e\u0432\u0435\u0440\u044f\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c. \u00ab\u0412\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0439\u00bb \u0445\u0438\u043d\u0442 <i>NOLOCK<\/i> \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"sql\">SELECT COUNT_BIG(*) FROM ... WITH(NOLOCK) <\/code><\/pre>\n<p>  \u041f\u043e \u0441\u0443\u0442\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u0434 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0438\u0437\u043e\u043b\u044f\u0446\u0438\u0438 <i>SERIALIZABLE<\/i> \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0445\u0438\u043d\u0442 <i>TABLOCKX<\/i>:<\/p>\n<pre><code class=\"sql\">SELECT COUNT_BIG(*) FROM ... WITH(TABLOCKX) <\/code><\/pre>\n<p>  \u0418 \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0432 \u0438\u0442\u043e\u0433\u0435\u2026 \u043c\u043e\u043d\u043e\u043f\u043e\u043b\u044c\u043d\u0443\u044e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0418 \u0442\u0443\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0448\u0430\u0442\u044c \u0441\u0430\u043c, \u0447\u0442\u043e \u0435\u043c\u0443 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041c\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u2014 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>  \u0415\u0449\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u044e:<\/p>\n<pre><code class=\"sql\">SELECT City, COUNT_BIG(*) FROM Person.[Address] --WHERE City = N'London' GROUP BY City <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0447\u0430\u0441\u0442\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0442\u0430\u0432\u043a\u0438-\u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"sql\">IF OBJECT_ID('dbo.CityAddress', 'V') IS NOT NULL     DROP VIEW dbo.CityAddress GO  CREATE VIEW dbo.CityAddress WITH SCHEMABINDING AS     SELECT City, [Rows] = COUNT_BIG(*)     FROM Person.[Address]     GROUP BY City GO  CREATE UNIQUE CLUSTERED INDEX IX ON dbo.CityAddress (City) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u043f\u043b\u0430\u043d \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u044c\u044e\u0445\u0438:<\/p>\n<pre><code class=\"sql\">SELECT City, COUNT_BIG(*) FROM Person.[Address] WHERE City = N'London' GROUP BY City  SELECT * FROM dbo.CityAddress WHERE City = N'London' <\/code><\/pre>\n<p>  \u041f\u043b\u0430\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u0431\u0435\u0437:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/536\/aae\/7b5\/536aae7b57b14f35a86eef8efa2f4ee4.png\"\/><\/p>\n<p>  \u042d\u0442\u0438\u043c \u043f\u043e\u0441\u0442\u043e\u043c \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 \u0432\u0441\u0435 \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0438\u0437\u043d\u0438 \u043d\u0435 \u0431\u044b\u0432\u0430\u0435\u0442. \u0418 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430 <i>SQL Server 2012 SP3 (11.00.6020)<\/i>.<br \/>  \u041f\u043b\u0430\u043d\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u0440\u0430\u043b \u0438\u0437 <i>SSMS<\/i> \u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e\u0439 \u0440\u0435\u0434\u0430\u043a\u0446\u0438\u0438 <a href=\"https:\/\/www.devart.com\/dbforge\/sql\/studio\/sql-query-profiler.html#header\"><i>dbForge Studio<\/i><\/a><\/p>\n<p>  PS. \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u0432\u0441\u0435\u043c \u0431\u044b\u043b\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c, \u0440\u0430\u0437 \u0443\u0436 \u0412\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \ud83d\ude42<\/p>\n<p>  \u041f\u043e\u0441\u0442 \u044f \u043f\u0438\u0441\u0430\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u2026 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0433\u0434\u0435-\u0442\u043e \u0437\u0430\u043a\u0440\u0430\u043b\u0438\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0441\u043b\u0438 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u0435 \u043b\u044f\u043f\u044b, \u0442\u043e \u043f\u0440\u043e\u0441\u044c\u0431\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438\u043b\u0438 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u0432 \u043f\u0440\u043e\u0444\u0438\u043b\u0435.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/271797\/\"> http:\/\/habrahabr.ru\/post\/271797\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0423 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c \u043f\u043e\u0434\u0431\u043e\u0440\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043b\u044e\u0431\u043b\u044e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043a \u0442\u0430\u0431\u043b\u0438\u0446\u0435? \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e, \u043d\u043e \u0435\u0441\u043b\u0438 \u043a\u043e\u043f\u043d\u0443\u0442\u044c \u0433\u043b\u0443\u0431\u0436\u0435, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043d\u044e\u0430\u043d\u0441\u043e\u0432 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043d\u0438\u043a\u0443.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e\u2026 \u042d\u0442\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u043c-\u0442\u043e \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430?<\/p>\n<pre><code class=\"sql\">SELECT COUNT(*) FROM Sales.SalesOrderDetail SELECT COUNT_BIG(*) FROM Sales.SalesOrderDetail <\/code><\/pre>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-269120","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269120"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/269120\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}