At the end of my last post, \u201cCSelCalcCombineFilters_ExponentialBackoff\u201d Calculator<\/a> I gave the following homework:<\/p>\n Homework assignment \u2013 add another member column to the mix that has a 0.100 selectivity (for example \u2013 county) and compare the estimates using a pre-2014 and 2014 CTP2 compatibility mode.<\/p><\/blockquote>\n Here is the answer-key.\u00a0 I\u2019ll start off with adding a new column called \u201ccounty\u201d to the member table (and yes \u2013 county gets a little involved for some cities like NYC, but let\u2019s just go with a uniform county association to city\/state for now):<\/p>\n And then next I\u2019ll revise my previous city\/state update script to include county:<\/p>\n Now, what row estimate will we get for the member table pre-2014 if we execute the following query?<\/p>\n We see the following estimated rows versus actual (keeping in mind that there are no multi-column stats to help us out):<\/p>\n Estimated number of rows is 10, but actual is 1000.<\/p>\n Given that we<\/em> know the three predicates are correlated, but SQL Server thinks they are independent (no multi-column stats), we can see the calculation is as follows:<\/p>\n Now if I switch to 2014 compatibility mode, I see the following estimated number of rows:<\/p>\n And I see the following query_optimizer_estimate_cardinality event output we see the following for the 2014 version of the plan:<\/p>\n <CalculatorList> So updating the formulas, how is the 177.828 derived?<\/p>\n So we see in 2014 CTP2 that instead of multiplying the selectivity of each predicate (again, assuming independence), the Exponential Backoff calculator is blunting the impact 10000*0.1*POWER(0.1,1\/2<\/span><\/strong>)*POWER(0.1,1\/4<\/span><\/strong>).<\/p>\n Still a skew \u2013 but less so.\u00a0 177.828 estimated vs. 10.\u00a0 And think it doesn\u2019t really matter?<\/p>\n For this example on my test system, pre-2014 the Clustered Index Scan was serial and fed to a Distribute Streams exchange operator, and with the new estimate, the operator is parallel.<\/p>\n Before:<\/p>\n\r\nALTER TABLE [dbo].[member]\r\nADD [county] varchar(15) NULL;\r\n<\/pre>\n
\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Minneapolis',\r\n[state_prov] = 'MN',\r\n[county] = 'Hennepin'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 0;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'New York',\r\n[state_prov] = 'NY',\r\n[county]='Manhattan'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 1;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Chicago',\r\n[state_prov] = 'IL',\r\n[county]='Cook'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 2;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Houston',\r\n[state_prov] = 'TX',\r\n[county]='Harrisburg'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 3;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Philadelphia',\r\n[state_prov] = 'PA',\r\n[county]='Philadelphia'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 4;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Phoenix',\r\n[state_prov] = 'AZ',\r\n[county]=''\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 5;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'San Antonio',\r\n[state_prov] = 'TX',\r\n[county]='Bexar'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 6;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'San Diego',\r\n[state_prov] = 'CA',\r\n[county]='San Diego'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 7;\r\n\r\nUPDATE\u00a0 [dbo].[member]\r\nSET\u00a0\u00a0\u00a0\u00a0 [city] = 'Dallas',\r\n[state_prov] = 'TX',\r\n[county]='Dallas'\r\nWHERE\u00a0\u00a0 [member_no] % 10 = 8;\r\nGO\r\n<\/pre>\n
\r\nSELECT\u00a0 m.[lastname],\r\nm.[firstname],\r\nSUM(c.[charge_amt]) AS [Total_Charge_amt]\r\nFROM\u00a0\u00a0\u00a0 [dbo].[member] AS [m]\r\nINNER JOIN [dbo].[charge] AS [c] ON\r\nm.[member_no] = c.[member_no]\r\nWHERE\u00a0\u00a0 [city] = 'Minneapolis' AND\r\n[state_prov] = 'MN' AND\r\n[county] = 'Hennepin'\r\nGROUP BY m.[lastname],\r\nm.[firstname]\r\nOPTION (RECOMPILE);\r\nGO\r\n<\/pre>\n
<\/a><\/p>\n
<\/a><\/p>\n
<\/a><\/p>\n
\n<FilterCalculator CalculatorName=”CSelCalcCombineFilters_ExponentialBackoff<\/span>” Conjunction=”true”>
\n<SubCalculator>
\n<FilterCalculator CalculatorName=”CSelCalcColumnInInterval” Selectivity=”0.100″ TableName=”[m]” ColumnName=”state_prov” StatId=”5″ \/>
\n<FilterCalculator CalculatorName=”CSelCalcColumnInInterval” Selectivity=”0.100″ TableName=”[m]” ColumnName=”county” StatId=”8″ \/>
\n<FilterCalculator CalculatorName=”CSelCalcColumnInInterval” Selectivity=”0.100″ TableName=”[m]” ColumnName=”city” StatId=”4″ \/>
\n<\/SubCalculator>
\n<\/FilterCalculator>
\n<\/CalculatorList><\/p>\n
<\/a><\/p>\n