<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Ian Jose's WebLog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/ianjo/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/ianjo/feed.xml</link>
    <description>This weblog is intended to help T-SQL developers get the best performing query plans from SQL Server.  Some of the posts describe simple mistakes that can be easily avoided.  Other posts describe complex solutions to limitations in SQL Server.  Lastly, so</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:09:14 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Ascending Keys and Auto Quick Corrected Statistics</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/ascending-keys-and-auto-quick-corrected-statistics</link>
      <pubDate>Mon, 24 Apr 2006 11:50:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2006/04/24/ascending-keys-and-auto-quick-corrected-statistics/</guid>
      <description><![CDATA[A common problem for some SQL Server applications are cases where data typically ascends.&nbsp; For...]]></description>
      <content:encoded><![CDATA[<P>A common problem for some SQL Server applications are cases where data typically ascends.&nbsp; For example, datetime columns where the column represents a current date.&nbsp; SQL Server builds statistics with the assumption that the data will by in large be similar in the future.&nbsp; However, when data typically ascends, most new&nbsp;insertions are out of the previously found range.&nbsp; This can lead to poorly performing plans as filters selecting recent data seem to exclude the entire relation when in fact a significant number of rows are included.</P>
<P>Trace flag 2389 and 2390, both new in SQL Server 2005 SP1, can help to address this problem.&nbsp; SQL Server 2005 SP1 begins to track the nature of columns via subsequent operations of updating statistics.&nbsp; When the statistics are seen to increase three times the column is branded ascending.&nbsp; If trace flag 2389 is set, and a column is branded ascending, and a covering index exists with the ascending column as the leading key, then the statistics will be updated automatically at query compile time.&nbsp; A statement is compiled to find the highest value and a new step is added at the end of the existing histogram to model the recently added data.&nbsp; </P>
<P>Trace flag 2390 enables the same behavior even if the ascending nature of the column is not known.&nbsp; As long as the column is a leading column in an index, then the optimizer will refresh the statisitc (with respect to the highest value) at query compile time.&nbsp; Never use 2390 alone since this would mean that this logic would be disabled as soon as the ascending nature of the column was known.</P>
<P>-- enable auto-quick-statistics update for known ascending keys</P>
<P><STRONG>dbcc traceon( 2389 )</STRONG></P>
<P>-- neable auto-quick-statistics update for all columns, known ascending or unknown</P>
<P><STRONG>dbcc traceon( 2389, 2390 )</STRONG> -- never enable 2390 alone</P>]]></content:encoded>
    </item>
    <item>
      <title>Query Processor Modelling Extensions in SQL Server 2005 SP1</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/query-processor-modelling-extensions-in-sql-server-2005-sp1</link>
      <pubDate>Mon, 24 Apr 2006 11:28:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2006/04/24/query-processor-modelling-extensions-in-sql-server-2005-sp1/</guid>
      <description><![CDATA[Trace flag 2301, available in SQL Server 2005 SP1, enhances the modelling ability of the query...]]></description>
      <content:encoded><![CDATA[<P>Trace flag 2301, available in SQL Server 2005 SP1, enhances the modelling ability of the query optimizer to better handle complex statements.&nbsp; Improved modelling can lead to dramatically faster performing query plans in some cases.&nbsp; These extensions to the query processor&nbsp;modelling abilities&nbsp;can lead to increased compile time and so should only be used by applications which compile infrequently.&nbsp; The model extensions are as follows:</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P><STRONG>Integer Modelling</STRONG></P>
<P>Normally, histogram modelling assumes that values between histogram steps are equally distributed to every numerical double code point.&nbsp; This modelling extension remembers, for integer base types, that values can only occur on integer code points and this improves cardinality estimates for inequality filters.</P>
<P><STRONG>Comprehensive Histogram Usage</STRONG></P>
<P>Normally, histograms are ignored when the cardinality of a relation dropps below the number of steps in a histogram.&nbsp; This is a heuristic which captures the liklihood that a histogram continues to describe a relation.&nbsp; This modelling extension&nbsp;applies the histogram in cardinality estimate regardless of the cardinality estimate for the relation.</P>
<P><STRONG>Base Containment Assumption</STRONG></P>
<P>Normally, when two relations are joined, we assume that X distinct code points in the same key range on input relation R will join with Y distinct code points in the same key range on input relation S such that MIN(X,Y) will find matches.&nbsp; This assumption is called Simple Containment.&nbsp; We assume that the smaller number of distinct code points match with code points from the other side.&nbsp; This modelling ignores the relative population of distinct code points in the base forms of R and S, and also ignores any filtering that has occured to the base forms for R and S before joining.&nbsp; Base containment applies the containment assumption only to the base relations and uses probabilistic methods to compute the degree of joining.&nbsp; In addition, implied filters are modelled correctly since their behavior is very different from orthogonal filters.</P>
<P><STRONG>Comprehensive Density Remapping</STRONG></P>
<P>Normally, when columns are CONVERTed only a small number of densities involving such columns are remapped to the new column definitions.&nbsp; Note that operations like convert rarely change the density of a column.&nbsp; Density is the measure of the number&nbsp;of duplicate values for each distinct value.&nbsp; With this modelling extension, all such remappings are applied which makes possible subsequent density matching for the purposes of cardinality estimation.&nbsp; In some cases, this can lead to excessive use of memory.</P>
<P><STRONG>Comprehensive Density Matching</STRONG></P>
<P>Normally, densities are matched when the very same base column is filtered or joined.&nbsp; With this modelling extension, the notion of equivalence of columns as a result of equi-joins is applied leading to more complete density matching for the purposes of improved cardinality estimation.</P></BLOCKQUOTE>
<P>These extentions all were developed to address customer found problems relation to poor performing query plans.&nbsp; If customers experience such poor performing plans where one or more of the above extentions may help, then trace flag 2301 may be applied.&nbsp; It is important to note that compile times will increase, and in some cases memory consumption can increase dramatically.&nbsp; Thus, it is important to apply this trace flag with care and test exhaustively before using in production.</P>
<P>&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Disabling Constant-Constant Comparison Estimation</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/disabling-constant-constant-comparison-estimation</link>
      <pubDate>Tue, 28 Mar 2006 16:43:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2006/03/28/disabling-constant-constant-comparison-estimation/</guid>
      <description><![CDATA[SQL Server 8.0 did not perform cardinality estimates based on the comparion of two constants.&nbsp;...]]></description>
      <content:encoded><![CDATA[<P>SQL Server 8.0 did not perform cardinality estimates based on the comparion of two constants.&nbsp; Instead, SQL Server 8.0 guessed at the resulting selectivity.&nbsp; The reasoning for this is that one or more of the constants may be statement parameters, which would change from one execution of the statement to the next.&nbsp; However, SQL Server 9.0 reversed this behavior and does esimate operator cardinality based on the comparison of two constants, when both values are available at compile time.&nbsp; Constant values are avilable at compile when when 1) they are literal constants or 2) they are parameters to a stored procedure or otherwise set at the nesting level above the the compilation of the statement.&nbsp; This change in behavior can be problematic for statements that optimize for one set of values but run for other sets of values.&nbsp; Applications that find adverse plan changes resulting from the change in behvior can revert behavior&nbsp;to that of the previous released by enabling trace flag <STRONG>2328</STRONG>.&nbsp; For example, to revert the behavior server wide, for the current invokation of SQL Server, one could run the following command:</P>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<P>dbcc traceon( 2328, -1)</P></BLOCKQUOTE>
<P>If running SQL Server 8.0, or SQL Server 9.0 with trace flag 2328 enabled, the optimizer will guess the selectivity arising from the comparion of two constants.&nbsp; The guess used is the same as comparing a column to an constant (where&nbsp;either the column&nbsp;distribution or the constant&nbsp;value, or both, is unknown).&nbsp; Since the selectivity of the comparison of two constants is either 0 or 1, one might think that a guess for such a comparion wouldbe 50%.&nbsp; Although there is a lot of logic in this behavior, for historic reasons, the guess used by SQL Server was very different.&nbsp; </P>
<P>Guessing the selectivity of a column-constant comparsion attempts to model several phenomena.&nbsp; First, when there are many rows, the selectivity is likely smaller because there could be more values from which to choose.&nbsp; Second, when there are many such conjuncts, it is more likely that subsequent conjuncts will be correlated with previous conjucts.&nbsp; SQL Server therefore reduces the selectivity from one to 0 by the exponent of the cardinality and the reducition factor is reduced with each guess.&nbsp; The following table shows the number of conjucts guessed and the resultant selectivity as a function of input table cardinality of N:</P>
<P>&nbsp;</P>
<P># Conjucts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cardinality&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Selectivity</P>
<P>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(3/4)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-1/4)</P>
<P>2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(11/16)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-5/16)</P>
<P>3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(43/64)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-21/64)</P>
<P>4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(171/256)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-85/256)</P>
<P>5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(170/256)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-86/256)</P>
<P>6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(169/256)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-87/256)</P>
<P>7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(168/256)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-88/256)</P>
<P>...</P>
<P>175&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(0/256)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;N^(-1)</P>]]></content:encoded>
    </item>
    <item>
      <title>Make Functions Schema-bound</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/make-functions-schema-bound</link>
      <pubDate>Tue, 31 Jan 2006 16:42:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2006/01/31/make-functions-schema-bound/</guid>
      <description><![CDATA[Create user defined functions with the SCHEMABINDING clause where possible.&nbsp; In the absence of...]]></description>
      <content:encoded><![CDATA[<p>Create user defined functions with the <strong>SCHEMABINDING</strong> clause where possible.&nbsp; In the absence of this clause, SQL Server must assume at compile time that statements using the function may bind to a function which accesses and updates data.&nbsp; Note that even if the UDFs do not access data or perform any updates, the SQL Server optimizer must be prepared for this in case the statement at run-time binds to a different UDF which does access and update data.&nbsp; This leads the optimizer to add halloween protection that is often unneccessary.&nbsp; This protection often manifests as Spool or Sort iterators in the plans and can dramatically slow down plan performance.&nbsp; Making UDFs schema-bound is necessary even if the UDF is uniquely named, and even if no UDFs access or update data.&nbsp; </p>
<p>This behavior has changed in SQL Server 2005, and applications that are porting from SQL Server 2000 to SQL Server 2005 should re-examine whether their UDFs can be schema bound and to make them schema bound if they are not already so marked.</p>
<p><strong><u>Background on Halloween Protection.</u></strong></p>
<p>"Halloween protection" in database systems refers to a solution for a problem that can occur in update queries. The problem&nbsp;occurs when an&nbsp;update itself affects the rows selected for update.&nbsp; For example, imagine a company wants to give every employee a 10% pay increase. If the update query is unlucky enough to walk the salary index then the same row may be selected, updated, the update moves the row ahead in the index, and then the row will be redundantly selected again and again.&nbsp; This problem is corrected by isolating the rows chosen from the effects of the update itself.&nbsp; For example, a&nbsp;SPOOL operation which stores all the rows to be updated outside of the context and any index can provide the necessary isolation. SORTs are also sufficient for isolation purposes.</p>]]></content:encoded>
    </item>
    <item>
      <title>Regularly Update Statistics for Ascending Keys</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/regularly-update-statistics-for-ascending-keys</link>
      <pubDate>Thu, 10 Nov 2005 17:02:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/regularly-update-statistics-for-ascending-keys/</guid>
      <description><![CDATA[Ascending key columns, such as IDENTITY columns or datetime columns representing real-world...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>Ascending key columns, such as IDENTITY columns or datetime columns representing real-world timestamps, can cause inaccurate statistics in tables with frequent INSERTS because new values all lie outside the histogram.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Consider updating statistics on such columns frequently with a batch job if your application seems to be getting inadequate query plans for queries that have a condition on the ascending key column. How often to run the batch job depends on your application. Consider daily or weekly intervals, or more often if needed for your application. Alternatively, trigger the job based on an application event, such as after a bulk load or after a certain number of INSERT operations.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Create Statistics for All Union Inputs</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/create-statistics-for-all-union-inputs</link>
      <pubDate>Thu, 10 Nov 2005 17:01:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/create-statistics-for-all-union-inputs/</guid>
      <description><![CDATA[When a query requires statistics on the result of a UNION or UNION ALL operation, create needed...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>When a query requires statistics on the result of a <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place>UNION</st1:place> or UNION ALL operation, create needed statistics uniformly on all <st1:place>UNION</st1:place> or UNION ALL inputs.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>It is not sufficient to create statistics on a subset of the <st1:place>UNION</st1:place> or UNION ALL inputs, even when those inputs are dominant.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>For example, </FONT></P>
<P class=Code style="MARGIN: 0in 0in 3pt; TEXT-INDENT: 0.5in"><SPAN style="COLOR: windowtext"><FONT size=2><FONT face="Courier New">SELECT * FROM Lineitem l WHERE EXISTS <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></P>
<P class=Code style="MARGIN: 0in 0in 3pt; TEXT-INDENT: 0.5in"><SPAN style="COLOR: windowtext"><FONT size=2><FONT face="Courier New">( SELECT * FROM Region1 r1 WHERE r1.C = l.C and r1.S = l.S <o:p></o:p></FONT></FONT></SPAN></P>
<P class=Code style="MARGIN: 0in 0in 3pt; TEXT-INDENT: 0.5in"><SPAN style="COLOR: windowtext"><FONT size=2><FONT face="Courier New">UNION SELECT * FROM Region2 r2 WHERE r2.C = l.C and r2.S = l.S ) <o:p></o:p></FONT></FONT></SPAN></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>In order for the EXISTS to be optimized accurately, it may be necessary to have a multi-column statistic on columns C and S in for Lineitem, Region1 and Region2.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>If the multi-column statistic does not exist in either Region1 or Region2 then the remaining statistics cannot be used to optimize this query.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Create Multi-Column Statistics</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/create-multi-column-statistics</link>
      <pubDate>Thu, 10 Nov 2005 17:01:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/create-multi-column-statistics/</guid>
      <description><![CDATA[When a query has a multi-column condition, consider creating multi-column statistics if you suspect...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>When a query has a multi-column condition, consider creating multi-column statistics if you suspect that the optimizer is not producing the best plan for the query. You get multi-column statistics as a by-product of creating a multi-column index, so if there is already a multi-column index that supports the multi-column condition, there is no need to create statistics explicitly. Auto create statistics only creates single-column statistics, never multi-column statistics. So if you need multi-column statistics, create them manually, or create a multi-column index.</FONT></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>Consider a query that accesses the AdventureWorks.Person.Contact table, and contains the following condition:</FONT></P>
<P class=Code style="MARGIN: 0in 0in 3pt"><SPAN style="COLOR: windowtext"><FONT size=2><FONT face="Courier New">FirstName = 'Catherine' AND LastName = 'Abel'<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></SPAN></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>To make selectivity estimation more accurate for this query, create the following statistics object:</FONT></P>
<P class=Code style="MARGIN: 0in 0in 3pt"><FONT size=2><FONT face="Courier New"><SPAN style="COLOR: windowtext">CREATE STATISTICS </SPAN><?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place><st1:City><SPAN style="COLOR: windowtext">LastFirst</SPAN></st1:City><SPAN style="COLOR: windowtext"> </SPAN><st1:State><SPAN style="COLOR: windowtext">ON</SPAN></st1:State></st1:place><SPAN style="COLOR: windowtext"> Person.Contact(LastName,FirstName)<o:p></o:p></SPAN></FONT></FONT></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>This statistics object will be useful for queries that contain predicates on LastName and FirstName, as well as LastName alone. In general, the selectivity of a predicate on any prefix of the set of columns in a multi-column statistics object can be estimated using that statistics object. </FONT></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT size=2><FONT face=Verdana>For a statistics object to fully support a multi-column condition, a <I style="mso-bidi-font-style: normal">prefix</I> of the columns in the multi-column statistics object must contain the columns in the condition. For example, a multi-column statistics object on columns (a,b,c) only partially supports the condition a=1 AND c=1; the histogram will be used to estimate the selectivity for a=1, but the density information for c will not be used since b is missing from the condition. Multi-column statistics on (a,c) or (a,c,b) would support the condition a=1 AND c=1, and density information could be used to improve selectivity estimation.<o:p></o:p></FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Auto-create and Auto-update Statistics</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/auto-create-and-auto-update-statistics</link>
      <pubDate>Thu, 10 Nov 2005 17:01:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/auto-create-and-auto-update-statistics/</guid>
      <description><![CDATA[For a large majority of SQL Server installations, the most important best practice is to use auto...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>For a large majority of SQL Server installations, the most important best practice is to use auto create and auto update statistics database-wide. Auto create and auto update statistics are on by default. If you observe bad plans and suspect that missing or out of date statistics are at fault, verify that auto create and auto update statistics are on. </FONT></P>
<P class=Text style="MARGIN: 3pt 0in"><FONT face=Verdana size=2>An alternative to enabling auto create statistics is enabled or make sure to manually create statistics using CREATE STATISTICS or <B style="mso-bidi-font-weight: normal">sp_createstats</B>.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Note that auto-statistics will not work for read-only databases.</FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Simplify statements with IF</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/simplify-statements-with-if</link>
      <pubDate>Thu, 10 Nov 2005 17:00:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/simplify-statements-with-if/</guid>
      <description><![CDATA[In some cases, a SQL statement can be simplified by using procedural logic.&nbsp; Instead of issuing...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT size=2><FONT face=Verdana>In some cases, a SQL statement can be simplified by using procedural logic.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Instead of issuing one complex query to cover multiple cases with <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place>UNION</st1:place> or OR, it is better to use and if..else logic to separate the cases into different SQL statements.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>In this way, the optimizer optimizes multiple simpler statements instead of a single complex statement and may be able to get better performing plans for each case.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>Limit Use of Multi-Statement TVFs and Table Variables</title>
      <link>https://docs.microsoft.com/archive/blogs/ianjo/limit-use-of-multi-statement-tvfs-and-table-variables</link>
      <pubDate>Thu, 10 Nov 2005 17:00:00 GMT</pubDate>
      <dc:creator><![CDATA[ianjo]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ianjo/2005/11/10/limit-use-of-multi-statement-tvfs-and-table-variables/</guid>
      <description><![CDATA[Limit use of multi-statement table valued functions (TVFs) and table variables in situations where...]]></description>
      <content:encoded><![CDATA[<P class=Text style="MARGIN: 3pt 0in"><FONT size=2><FONT face=Verdana>Limit use of multi-statement table valued functions (TVFs) and table variables in situations where getting a high-performance plan is requied.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Both multi-statement TVFs and table variables have no statistics. The optimizer must guess the size of their results. Similarly, result column do not have statistics, and the optimizer must resort to guesses for predicates involving these columns.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>If a bad plan results because of these guesses, consider using an in-lined TVF, or standard table or temporary table as a temporary holding place for the results of the TVF, or a replacement for the table variable. This will allow the optimizer to use better cardinality estimates.<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>Note that this technique may also lead to an increased number of statement recompilations.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>]]></content:encoded>
    </item>
  </channel>
</rss>