<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Query Optimizer', 'Performance', 'Optimization', and 'Check Constraints'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Query+Optimizer,Performance,Optimization,Check+Constraints&amp;orTags=0</link><description>Search results matching tags 'Query Optimizer', 'Performance', 'Optimization', and 'Check Constraints'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>The Query Optimizer and Contradiction Detection</title><link>http://sqlblog.com/blogs/ben_nevarez/archive/2009/08/04/the-query-optimizer-and-contradiction-detection.aspx</link><pubDate>Tue, 04 Aug 2009 06:56:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15733</guid><dc:creator>Ben Nevarez</dc:creator><description>&lt;P class=MsoNormal&gt;One of the many interesting topics I found while working as technical editor of the SQL Server 2008 Internals book was the concept of contradiction detection. So, in this post I will to try to expand on this topic and provide some additional examples.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;Contradiction detection is performed by SQL Server during the early steps of the query optimization process. During this process the Query Optimizer tries to find contradictions that can be removed and can make the query perform better. Since these parts of the query are not executed at all, SQL Server saves resources like I/O, locks, memory and CPU, making the query to be executed faster. For example, the Query Optimizer may know that no records can satisfy a predicate even before touching any page of data.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;A contradiction may be related to a check constraint, or may be related to the way the query is written, that is, the query itself contains a contradiction. Let us explore both scenarios and analyze the execution plans that are generated on each case.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;First, I need to a table with a check constraint. The following code creates a table that stores information about classic rock albums and its check constraint validates that every record entered was released before 1990.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- create table &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;create&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;table&lt;/SPAN&gt; albums&lt;SPAN style="COLOR:blue;"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;( &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;name &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;band &lt;SPAN style="COLOR:blue;"&gt;varchar&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;40&lt;SPAN style="COLOR:gray;"&gt;),&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;album_year &lt;SPAN style="COLOR:blue;"&gt;smallint&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;, &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;constraint&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; check_year &lt;SPAN style="COLOR:blue;"&gt;check &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;lt;&lt;/SPAN&gt; 1990&lt;SPAN style="COLOR:gray;"&gt;)) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- add some records &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;insert&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;into&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;values &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'Machine Head'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'Deep Purple'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; 1972&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;insert&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;into&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;values &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'A Night at the Opera'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'Queen'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; 1975&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;insert&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;into&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;values &lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR:red;"&gt;'British Steel'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="COLOR:red;"&gt;'Judas Priest'&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; 1980&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;So, if I run a query to list all the records released, let us say before 1980, the execution plan uses a Table Scan operator, which is exactly what I expected for this scenario.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;from&lt;/SPAN&gt; albums &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;lt;&lt;/SPAN&gt; 1980 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;A href="http://sqlblog.com/blogs/ben_nevarez/clip_image002_34F25E56.jpg"&gt;&lt;IMG title=clip_image002 style="BORDER-TOP-WIDTH:0px;DISPLAY:block;BORDER-LEFT-WIDTH:0px;FLOAT:none;BORDER-BOTTOM-WIDTH:0px;MARGIN-LEFT:auto;MARGIN-RIGHT:auto;BORDER-RIGHT-WIDTH:0px;" height=117 alt=clip_image002 src="http://sqlblog.com/blogs/ben_nevarez/clip_image002_thumb_4769518A.jpg" width=271 border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;Check Constraint &lt;/B&gt;
&lt;P&gt;But what about if somebody tries to request all the records released, for example, after 1995, like in the following query? Does the Query Optimizer know that no records will be returned even before looking at the data on the table?&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;from&lt;/SPAN&gt; albums &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;gt;&lt;/SPAN&gt; 1995 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;In this case the Query Optimizer should know that because of the existing check constraint the previous query returns no records. So if I execute this query there is no need for SQL Server to access the data on the table, right? But surprisingly, the resulting execution plan still shows the Table Scan operator. Why?&lt;/P&gt;
&lt;P class=MsoNormal&gt;Actually, there is another optimization called autoparameterization, which is closely related to the&amp;nbsp;trivial plan feature and&amp;nbsp;that&amp;nbsp;overrides contradiction detection. To avoid this&amp;nbsp;optimization I can use some features like query hints, joins, etc. like in the following example&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;from&lt;/SPAN&gt; albums &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;gt;&lt;/SPAN&gt; 1995 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;option &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;maxdop&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; 1&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;Once I change the query to use a query hint,&amp;nbsp;the execution plan does not access the table at all, and instead it is just using a Constant Scan operator. &lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;A href="http://sqlblog.com/blogs/ben_nevarez/clip_image004_2BF2F206.jpg"&gt;&lt;IMG title=clip_image004 style="BORDER-TOP-WIDTH:0px;DISPLAY:block;BORDER-LEFT-WIDTH:0px;FLOAT:none;BORDER-BOTTOM-WIDTH:0px;MARGIN-LEFT:auto;MARGIN-RIGHT:auto;BORDER-RIGHT-WIDTH:0px;" height=96 alt=clip_image004 src="http://sqlblog.com/blogs/ben_nevarez/clip_image004_thumb_2C8D516D.jpg" width=270 border=0&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;Now, see what happens if I disable the check constraint&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- disable constraint &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;alter&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;table&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;nocheck&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;constraint&lt;/SPAN&gt; check_year &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;This time running the last query uses a Table Scan operator again as the optimizer can not longer use the check constraint.&lt;/P&gt;
&lt;P class=MsoNormal&gt;Finally, there are two choices to enable back the existing check constraint. If I ask SQL Server to enable the constraint and validate the existing data, the constraint will be enabled only if all the data complies with the check constraint definition. If I ask not to validate the existing data, the check constraint will be enabled but only the new records will be validated.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;Of course the resulting execution plan of my query will be different depending on the selected choice. If the check constraint is enabled validating the existing data, running the same query again (and including the query hint) will use the Constant Scan operator. But enabling the constraint without validating the existing data will again result in a Table Scan even when no records are returned. Basically, in this last case the query optimizer can not trust the check constraint.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;You can test yourself the resulting execution plans of the query after enabling the check constraint with any of these two commands&lt;/P&gt;
&lt;P class=MsoNormal&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- enable constraint validating existing data &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;alter&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;table&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;with&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;check&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;check&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;constraint&lt;/SPAN&gt; check_year &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:green;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;-- enable constraint without validating existing data &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;alter&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:blue;"&gt;table&lt;/SPAN&gt; albums &lt;SPAN style="COLOR:blue;"&gt;with&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;nocheck&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;check&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;constraint&lt;/SPAN&gt; check_year &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;By the way, you can use the following query to see if a check constraint is not trusted, that is, if it has not been verified for all the records on the table.&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; name&lt;SPAN style="COLOR:gray;"&gt;,&lt;/SPAN&gt; is_not_trusted &lt;SPAN style="COLOR:blue;"&gt;from&lt;/SPAN&gt; &lt;SPAN style="COLOR:green;"&gt;sys&lt;/SPAN&gt;&lt;SPAN style="COLOR:gray;"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR:green;"&gt;check_constraints &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight:normal;"&gt;Contradicting Predicate &lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The second type of contradiction case is when the query itself contains a contradiction. Take a look at this query&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; &lt;SPAN style="COLOR:gray;"&gt;*&lt;/SPAN&gt; &lt;SPAN style="COLOR:blue;"&gt;from&lt;/SPAN&gt; albums &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;lt;&lt;/SPAN&gt; 1970 &lt;SPAN style="COLOR:gray;"&gt;and&lt;/SPAN&gt; album_year &lt;SPAN style="COLOR:gray;"&gt;&amp;gt;&lt;/SPAN&gt; 1980 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;option &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:gray;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;COLOR:blue;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt;maxdop&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Courier New';mso-no-proof:yes;"&gt; 1&lt;SPAN style="COLOR:gray;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/SPAN&gt;Same as before the execution plan for this query will use a Table Scan when the query hint is not used even when it is so obvious that there is a contradiction and no records should be returned. &lt;/P&gt;
&lt;P class=MsoNormal&gt;Once I add the query hint,&amp;nbsp;the Table Scan again is gone and only a Constant Scan operator is used.&lt;/P&gt;</description></item></channel></rss>