{"id":341914,"date":"2022-11-29T21:00:23","date_gmt":"2022-11-29T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=341914"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=341914","title":{"rendered":"<span>\u0421\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0410\u0432\u0442\u043e\u0440 <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/user\/viewprofilepage\/user-id\/422394\" rel=\"noopener noreferrer nofollow\">Liwei Yin<\/a><\/p>\n<p>\u041e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e\u00a001.11.2022<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/698354\/\" rel=\"noopener noreferrer nofollow\">SQL Server Cardinality Estimation: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443<\/a> \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a SQL Server \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443.\u00a0\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f OLTP \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/samples\/adventureworks-install-configure?view=sql-server-ver16&amp;tabs=ssms\" rel=\"noopener noreferrer nofollow\">AdventureWorks2019<\/a>.<\/p>\n<pre><code class=\"sql\">------- \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 ------------------------------------------- alter database [AdventureWorks2019] set compatibility_level=150 go use [AdventureWorks2019] go if exists(select 1 from sys.tables where name='SalesOrderDetail') drop table SalesOrderDetail go select * into SalesOrderDetail from Sales.SalesOrderDetail-- \u0438\u043c\u043f\u043e\u0440\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Go -- \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c create statistics I_ProductID_UnitPrice on SalesOrderDetail(ProductID,UnitPrice) with fullscan create statistics I_UnitPrice  on SalesOrderDetail(UnitPrice) with fullscan ------- \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 -------------------------------------------<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 SQL Server Cardinality Estimation (\u0434\u0430\u043b\u0435\u0435 \u0421\u0415) \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043d\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043e\u0446\u0435\u043d\u043a\u0438, \u0442.\u0435. \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0438\u0436\u0435 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438.\u00a0<\/p>\n<h2>\u041d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f CE-2017\/2019-db_compatibility_level >= 140<\/h2>\n<p>a)\u00a0\u0418\u0437\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c) \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u00a0<strong>\u0444\u043e\u0440\u043c\u0443\u043b\u0435<\/strong>:\u00a0<strong>MAX(min(&#8216;<\/strong><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/database-console-commands\/dbcc-show-statistics-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">All Density<\/a><strong>&#8216;,p0,p1,p2,p3),p0*p1*p2*p3)<\/strong><\/p>\n<p>b)\u00a0All Density (<a href=\"https:\/\/learn.microsoft.com\/ru-ru\/sql\/t-sql\/database-console-commands\/dbcc-show-statistics-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c<\/a>) \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c. p0,p1,p2,p3 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 WHERE, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c p0&lt;p1&lt;p2&lt;p3.<\/p>\n<p>c) \u0415\u0441\u043b\u0438 \u0443 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 4, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f.<\/p>\n<h3>CE \u0434\u043b\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 150<\/h3>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=150 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/814\/e95\/54b\/814e9554bd0086e33879becadaef7431.png\" width=\"997\" height=\"176\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/814\/e95\/54b\/814e9554bd0086e33879becadaef7431.png\"\/><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u00a0\u00a0\u00a0 \u0420\u0430\u0441\u0447\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 341.<\/p>\n<p>2)\u00a0\u00a0\u00a0\u00a0 \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a:\u00a0<strong>max(min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c&#8217;,P1,P2),P1*P2)<\/strong>\u00a0<strong> * cardinality<\/strong><\/p>\n<p>a) \u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d) \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c) 121317<\/p>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_ProductID_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ef5\/f86\/e90\/ef5f86e90a5dd50fad9928fd8a86ed25.png\" width=\"892\" height=\"508\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ef5\/f86\/e90\/ef5f86e90a5dd50fad9928fd8a86ed25.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/feb\/9d4\/c0d\/feb9d4c0daa662adfcff6f798030f802.png\" width=\"836\" height=\"574\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/feb\/9d4\/c0d\/feb9d4c0daa662adfcff6f798030f802.png\"\/><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u041f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435: max(min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c&#8217;,p0,p1),p0*p1) *cardinality<\/p>\n<p>max(\u00a0 min(0.001321004,0.03864256,0.07275979),0.03864256*0.07275979)*121317<\/p>\n<p>=max(0.001321004,0.03864256*0.07275979)*121317<\/p>\n<p>=max(0.001321004,0.0028116245506624)*121317<\/p>\n<p>=0.0028116245506624*121317=341.09785561, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0434\u043e 341.<\/p>\n<p>4) \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code class=\"sql\">Dbcc traceon(3604,2363) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Cardinality using multi-column statistics 0.001321 and with independence assumption 0.00281163. Picking cardinality 0.00281163 Selectivity: 0.00281163 Stats collection generated:   CStCollFilter(ID=3, CARD=341.098)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<h3>\u0412\u0435\u0440\u0441\u0438\u044f CE-2016-db_compatibility_level=130<\/h3>\n<p>\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0\u0430) \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c<strong>:\u00a0min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c,p0,p1,p2,p3)<\/strong><\/p>\n<p>\u00a0 \u00a0 \u00a0b) \u00ab\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\u00bb \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c.<\/p>\n<p>\u00a0 \u00a0 \u00a0c) p0,p1,p2,p3 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 WHERE, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c p0&lt;p1&lt;p2&lt;p3.<\/p>\n<p>\u00a0 \u00a0 \u00a0d) \u0415\u0441\u043b\u0438 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 4, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 4199, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f DB_compatibility_level 140\/150.<\/p>\n<p>\u0414\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0438 CE \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b 130 \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=130 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/67b\/8ed\/0ec\/67b8ed0ec5895a2d34bf76cfb7aed41f.png\" width=\"998\" height=\"210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/67b\/8ed\/0ec\/67b8ed0ec5895a2d34bf76cfb7aed41f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u00a0\u00a0\u00a0 \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 160.<\/p>\n<p>2)\u00a0\u00a0\u00a0\u00a0 \u0412\u043e\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a:\u00a0<strong>min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\u2019,p0,p1)*cardinality<\/strong><\/p>\n<p>a)\u00a0\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d)\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c 121317<\/p>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_ProductID_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5bf\/cd9\/79b\/5bfcd979bf4e88b5dd5b9fe89af7f330.png\" width=\"892\" height=\"508\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5bf\/cd9\/79b\/5bfcd979bf4e88b5dd5b9fe89af7f330.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/60e\/681\/c48\/60e681c484a275be8bc87ba0c9d48237.png\" width=\"836\" height=\"574\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/60e\/681\/c48\/60e681c484a275be8bc87ba0c9d48237.png\"\/><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443: min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432&#8217;,p0,p1) * \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<p>4)\u00a0MIN(0,001321004,0,03864256,0,07275979)*121317=0,001321004*121317=160,260242268, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e 160.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code>Dbcc traceon(3604,2363,) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Selectivity: 0.001321 Stats collection generated:   CStCollFilter(ID=3, CARD=160.26)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<h3>\u0412\u0435\u0440\u0441\u0438\u044f CE-2014-db_compatibility_level=120<\/h3>\n<p>\u00a0<\/p>\n<p>SQL 2014 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"https:\/\/habr.com\/ru\/post\/698354\/\" rel=\"noopener noreferrer nofollow\">SQL Server Cardinality Estimation: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443<\/a>. \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0442\u0430\u043a\u0430\u044f: <strong>p0 * p1^(1\/2) * p2^(1\/4)* p3^(1\/8)<\/strong><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 4199, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f DB_compatibility_level 140\/150.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u0441\u0438\u0438 CE \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 120 \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=120 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b32\/e56\/539\/b32e565390410accb7636b56258d0480.png\" width=\"998\" height=\"210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b32\/e56\/539\/b32e565390410accb7636b56258d0480.png\"\/><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 12650.<\/p>\n<p>2)\u00a0\u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a: <strong>p0 * p1^(1\/2<\/strong>)<strong>\u00a0*cardinality.<\/strong><\/p>\n<p>a)\u00a0\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d)\u00a0\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c 121317<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9e9\/886\/25c\/9e988625cb3ea8e090274e2fb2fba997.png\" width=\"892\" height=\"508\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9e9\/886\/25c\/9e988625cb3ea8e090274e2fb2fba997.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c10\/55d\/5ce\/c1055d5ceffecdcd8f07402c7b869448.png\" width=\"836\" height=\"574\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c10\/55d\/5ce\/c1055d5ceffecdcd8f07402c7b869448.png\"\/><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u00a0\u00a0\u00a0 \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443:\u00a0<strong>p0 * p1^(1\/2)<\/strong>\u00a0 <strong>* cardinality<\/strong><\/p>\n<p>0,03864256*0,07275979^(1\/2)*121317=0,0104235*121317=1264,547750, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e 1265.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code class=\"sql\">Dbcc traceon(3604,2363,) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Selectivity: 0.0104235 Stats collection generated:   CStCollFilter(ID=2, CARD=1264.54)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d18\/827\/ca1\/d18827ca12821e719ea3abaf93526501.png\" width=\"998\" height=\"655\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d18\/827\/ca1\/d18827ca12821e719ea3abaf93526501.png\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/702366\/\"> https:\/\/habr.com\/ru\/post\/702366\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0410\u0432\u0442\u043e\u0440 <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/user\/viewprofilepage\/user-id\/422394\" rel=\"noopener noreferrer nofollow\">Liwei Yin<\/a><\/p>\n<p>\u041e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e\u00a001.11.2022<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/698354\/\" rel=\"noopener noreferrer nofollow\">SQL Server Cardinality Estimation: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443<\/a> \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u043e\u0441\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a SQL Server \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443.\u00a0\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440, \u0438 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f OLTP \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 <a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/samples\/adventureworks-install-configure?view=sql-server-ver16&amp;tabs=ssms\" rel=\"noopener noreferrer nofollow\">AdventureWorks2019<\/a>.<\/p>\n<pre><code class=\"sql\">------- \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 ------------------------------------------- alter database [AdventureWorks2019] set compatibility_level=150 go use [AdventureWorks2019] go if exists(select 1 from sys.tables where name='SalesOrderDetail') drop table SalesOrderDetail go select * into SalesOrderDetail from Sales.SalesOrderDetail-- \u0438\u043c\u043f\u043e\u0440\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 Go -- \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0432\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c create statistics I_ProductID_UnitPrice on SalesOrderDetail(ProductID,UnitPrice) with fullscan create statistics I_UnitPrice  on SalesOrderDetail(UnitPrice) with fullscan ------- \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 -------------------------------------------<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 SQL Server Cardinality Estimation (\u0434\u0430\u043b\u0435\u0435 \u0421\u0415) \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043d\u0435 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043e\u0446\u0435\u043d\u043a\u0438, \u0442.\u0435. \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u0435\u0441\u0442\u0438 \u0441\u0435\u0431\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443, \u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043d\u0438\u0436\u0435 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0440\u043e\u0432\u043d\u0435\u0439 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438.\u00a0<\/p>\n<h2>\u041d\u043e\u0432\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f CE-2017\/2019-db_compatibility_level >= 140<\/h2>\n<p>a)\u00a0\u0418\u0437\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c) \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u00a0<strong>\u0444\u043e\u0440\u043c\u0443\u043b\u0435<\/strong>:\u00a0<strong>MAX(min(&#8216;<\/strong><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/database-console-commands\/dbcc-show-statistics-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">All Density<\/a><strong>&#8216;,p0,p1,p2,p3),p0*p1*p2*p3)<\/strong><\/p>\n<p>b)\u00a0All Density (<a href=\"https:\/\/learn.microsoft.com\/ru-ru\/sql\/t-sql\/database-console-commands\/dbcc-show-statistics-transact-sql?view=sql-server-ver16\" rel=\"noopener noreferrer nofollow\">\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c<\/a>) \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c. p0,p1,p2,p3 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 WHERE, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c p0&lt;p1&lt;p2&lt;p3.<\/p>\n<p>c) \u0415\u0441\u043b\u0438 \u0443 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 4, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f.<\/p>\n<h3>CE \u0434\u043b\u044f \u0443\u0440\u043e\u0432\u043d\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 150<\/h3>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=150 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u00a0\u00a0\u00a0 \u0420\u0430\u0441\u0447\u0435\u0442\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 341.<\/p>\n<p>2)\u00a0\u00a0\u00a0\u00a0 \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a:\u00a0<strong>max(min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c&#8217;,P1,P2),P1*P2)<\/strong>\u00a0<strong> * cardinality<\/strong><\/p>\n<p>a) \u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d) \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c, \u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c) 121317<\/p>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_ProductID_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u041f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435: max(min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u0434\u0432\u0443\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c&#8217;,p0,p1),p0*p1) *cardinality<\/p>\n<p>max(\u00a0 min(0.001321004,0.03864256,0.07275979),0.03864256*0.07275979)*121317<\/p>\n<p>=max(0.001321004,0.03864256*0.07275979)*121317<\/p>\n<p>=max(0.001321004,0.0028116245506624)*121317<\/p>\n<p>=0.0028116245506624*121317=341.09785561, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u043c \u0434\u043e 341.<\/p>\n<p>4) \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code class=\"sql\">Dbcc traceon(3604,2363) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Cardinality using multi-column statistics 0.001321 and with independence assumption 0.00281163. Picking cardinality 0.00281163 Selectivity: 0.00281163 Stats collection generated:   CStCollFilter(ID=3, CARD=341.098)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<h3>\u0412\u0435\u0440\u0441\u0438\u044f CE-2016-db_compatibility_level=130<\/h3>\n<p>\u00a0<\/p>\n<p>\u00a0 \u00a0 \u00a0\u0430) \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c<strong>:\u00a0min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c,p0,p1,p2,p3)<\/strong><\/p>\n<p>\u00a0 \u00a0 \u00a0b) \u00ab\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\u00bb \u2014 \u044d\u0442\u043e \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c.<\/p>\n<p>\u00a0 \u00a0 \u00a0c) p0,p1,p2,p3 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 WHERE, \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c p0&lt;p1&lt;p2&lt;p3.<\/p>\n<p>\u00a0 \u00a0 \u00a0d) \u0415\u0441\u043b\u0438 \u0432 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 4 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 4, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 4199, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f DB_compatibility_level 140\/150.<\/p>\n<p>\u0414\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0438 CE \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b 130 \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=130 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u00a0\u00a0\u00a0 \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 160.<\/p>\n<p>2)\u00a0\u00a0\u00a0\u00a0 \u0412\u043e\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a:\u00a0<strong>min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\u2019,p0,p1)*cardinality<\/strong><\/p>\n<p>a)\u00a0\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d)\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c 121317<\/p>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_ProductID_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443: min(&#8216;\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432&#8217;,p0,p1) * \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<p>4)\u00a0MIN(0,001321004,0,03864256,0,07275979)*121317=0,001321004*121317=160,260242268, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e 160.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code>Dbcc traceon(3604,2363,) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Selectivity: 0.001321 Stats collection generated:   CStCollFilter(ID=3, CARD=160.26)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<h3>\u0412\u0435\u0440\u0441\u0438\u044f CE-2014-db_compatibility_level=120<\/h3>\n<p>\u00a0<\/p>\n<p>SQL 2014 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0431\u044b\u043b \u043e\u043f\u0438\u0441\u0430\u043d \u0432 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"https:\/\/habr.com\/ru\/post\/698354\/\" rel=\"noopener noreferrer nofollow\">SQL Server Cardinality Estimation: \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443<\/a>. \u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0442\u0430\u043a\u0430\u044f: <strong>p0 * p1^(1\/2) * p2^(1\/4)* p3^(1\/8)<\/strong><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0435\u0441\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 4199, \u0442\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0434\u043b\u044f DB_compatibility_level 140\/150.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u0441\u0438\u0438 CE \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 120 \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p>\n<pre><code class=\"sql\">alter database [AdventureWorks2019] set compatibility_level=120 select * from SalesOrderDetail where ProductID=870 and UnitPrice=4.99 option(recompile)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>1)\u00a0\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u0442\u0440\u043e\u043a 12650.<\/p>\n<p>2)\u00a0\u0424\u043e\u0440\u043c\u0443\u043b\u0430 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u0441\u0442\u0440\u043e\u043a: <strong>p0 * p1^(1\/2<\/strong>)<strong>\u00a0*cardinality.<\/strong><\/p>\n<p>a)\u00a0\u041e\u0431\u0449\u0430\u044f \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: 0,001321004<\/p>\n<p>b)\u00a0p0 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (ProductID) \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 where, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 4688\/121317=0,03864256.<\/p>\n<p>c)\u00a0p1 \u2014 \u0441\u0435\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430 (UnitPrice), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8827\/121317=0,07275979.<\/p>\n<p>d)\u00a0\u00a0\u043a\u0430\u0440\u0434\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c 121317<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">dbcc show_statistics(SalesOrderDetail,I_UnitPrice)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>3)\u00a0\u00a0\u00a0\u00a0 \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443\u043b\u0443:\u00a0<strong>p0 * p1^(1\/2)<\/strong>\u00a0 <strong>* cardinality<\/strong><\/p>\n<p>0,03864256*0,07275979^(1\/2)*121317=0,0104235*121317=1264,547750, \u043e\u043a\u0440\u0443\u0433\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e 1265.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0444\u043b\u0430\u0433 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 2363.<\/p>\n<pre><code class=\"sql\">Dbcc traceon(3604,2363,) ------------trace flag 2363 output----------------- Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].ProductID from stats with id 2 Loaded histogram for column QCOL: [AdventureWorks2019].[dbo].[SalesOrderDetail].UnitPrice from stats with id 3 Selectivity: 0.0104235 Stats collection generated:   CStCollFilter(ID=2, CARD=1264.54)       CStCollBaseTable(ID=1, CARD=121317 TBL: SalesOrderDetail) End selectivity computation ------------trace flag 2363 output-----------------<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/702366\/\"> https:\/\/habr.com\/ru\/post\/702366\/<\/a><br \/><\/br><\/br><\/p>\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-341914","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341914","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=341914"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/341914\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=341914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=341914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=341914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}