This post is a continuation of the SQL Server 2014 Cardinality Estimator enhancements exploration series:<\/p>\n
In the previous post I showed you how to start using the new SQL Server 2014 CE model, but what different does it actually make?<\/p>\n
Of course your own mileage may vary (and you should expect it to), but I thought I would kick the tires a bit by comparing root-level cardinality estimate skews for a specific workload against the AdventureWorks2008R2 database<\/a>.\u00a0 I used Jonathan\u2019s \u201cAdventureWorks BOL Workload.sql\u201d script that he put together for use in the context of The AdventureWorks2008R2 Books Online Random Workload Generator<\/a> (I made a few minor adjustments \u2013 for example, removing the queries that referenced the deprecated COMPUTE).<\/p>\n The query I used for extracting estimated vs. actual last rows was as follows (for both tests):<\/p>\n Of course, root level cardinality skews don\u2019t really give us the full<\/em> picture (see my post Detecting Cardinality Estimate Issues with sys.dm_exec_query_stats<\/a>), especially for significant skews that are in the leaf-level or intermediate levels of the plan that work themselves out by the time they reach the root. But this informal test was a way for me to get a general feel for changes across several statements in a workload.<\/p>\n Now for these tests, I had query_hash values that would appear for the old-CE and not the new-CE and for the new-CE and not the old-CE.\u00a0 Rather than run down that bunny trail (background requests, for example), I just focused for the time being on those query_hash values that joined consistently across each test run.<\/p>\n Here is what I saw \u2013 adding a bit of color to the noteworthy changes of old-CE vs. new-CE.<\/p>\n\n
\r\nSELECT\u00a0 s.[query_hash],\r\np.[query_plan].value('(\/\/@EstimateRows)[1]', 'varchar(128)') AS [estimated_rows],\r\ns.[last_rows]\r\nFROM\u00a0\u00a0\u00a0 sys.[dm_exec_query_stats] AS [s]\r\nCROSS APPLY sys.[dm_exec_sql_text](sql_handle) AS [t]\r\nCROSS APPLY sys.[dm_exec_query_plan](plan_handle) AS [p]\r\nWHERE\u00a0\u00a0 DATEDIFF(mi, s.[last_execution_time], GETDATE()) < 1\r\nGO\r\n<\/pre>\n