Re: many "or" operation make system choose incorrect index



Gert-Jan Strik (sorry@xxxxxxxxxxxxxxxxxxxxx) writes:
Please note that there is a certain point at which the compilation time
grows a lot for each addition predicate you add to the WHERE clause. If
the compilation time exceeds the estimated gains, the optimizer will
stop compilation and simply choose a "good enough" plan.

Indeed. Many OR clauses, or many values in IN can result in horrendeous
compilation times. SQL 2005 fare a lot better than SQL 2000, but the cost
is still high.

One thing I've notice that when there are more than 63 values (I think
that was the value), SQL Server stashes all the constants into a work
table, and you get the same result as you had the values in a temp table.
At least that was what I saw in a test that I ran.



--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Problem when changing Views
    ... RecordSource of a Form but in order to speed things up I made into a ... "The Order By clause is invalid in Views ... ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Why Same query results in two different # in SQL Server vs MS Access
    ... it's impossible to tell what the reason might be from ... Move the conditions in the HAVING clause to the WHERE clause. ... Access and SQL Server, ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: what occurs in a comparison when a value is NULL
    ... will evaluate to UNKNOWN and b.ofc is = 1, and the isnull expression ... The next WHEN clause will be evaluated as b.ofc = 0 isn't TRUE here. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • RE: SQL 2005 Management Studio cant edit text rows with > 4000 ch
    ... trying to edit the text field, the problem is the where clause that ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: MS SQL IF ELSE condition checking
    ... In this particular case, use coalesce: ... clause is true, the value of the corresponding THEN clause is returned. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)