Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.databases.ms-sqlserver    |    Notorious Rube Goldberg contraption    |    19,505 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 17,803 of 19,505    |
|    Erland Sommarskog to Emin    |
|    Re: How do you prevent predicate optimiz    |
|    07 May 10 23:38:33    |
      a9c7e709       From: esquel@sommarskog.se              Emin (emin.shopper@gmail.com) writes:       > I would like to explicitly prevent SQL Server 2005 from rewriting a       > query in my WHERE clause because the rewrite slows things down by many       > orders of magnitude.       >       > I have a query like       >       > SELECT * FROM A WHERE b in (31, 78)       >       > which takes forever (times out actually).       >       > If I instead do SELECT * FROM A WHERE b = 31 or if I do SELECT * FROM       > A WHERE b = 78, each query runs very quickly but the combination is       > incredibly slow despite the fact that I have indexes on appropriate       > things.       >       > After some investigation with the query optimizer, I determined that       > SQL Server is rewriting the predicate "b in (31, 78)" as (b>=31) AND       > (b<=78) as an intermediate step. I suspect this makes the query take a       > long time because there are *LOTS* of records with b>=31 and b<=78.              If that is happening, I would suspect that statistics are out       of date. What happens if you run UPDATE STATISTICS WITH FULLSCAN       on the table?              --       Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se              Links for SQL Server Books Online:       SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx       SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx       SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca