Re: Using CAST() in WHERE Clause hangs/slows Query

From: Wayne Snyder (wsnyder_at_computeredservices.com)
Date: 05/26/04


Date: Wed, 26 May 2004 07:17:22 -0400

When you use a column in a WHERE clause which has any function on it, SQL
Server can NOT use index statistics to determine which is the best index to
use. The optimizer then uses some hard coded estimates as to the estimated
number of rows that may be returned...THen picks the best index based on the
hard coded estimates.

Although using functions in where clauses does not actually prevent the use
of indexes, the inability to see index statistics increases the liklihood
that a less than optimal index or even a table scan will be chosen.....

-- 
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"ckaneko" <ckaneko@ffi-hq.com> wrote in message
news:OD95ibpQEHA.3140@TK2MSFTNGP11.phx.gbl...
> Thanks everyone.  I did remove the casting and it did make a big
difference!
> I created the query in a view then placed it into a stored procedure.  The
> view placed the Cast function in there.
>
> I still don't understand as to why the query runs quickly sometimes and
> other times it doesn't.
>
> "Guillaume" <mssupport@candg2.com> wrote in message
> news:310186B3-1158-4766-BB4F-07D239A65D77@microsoft.com...
> > I don't pretend to be giving a definitive answer on this, but from what
I
> know, when you use a function (like CAST) on a column it disables the use
of
> any regular index on that column.
> >
> > If you have a lot of data, the simple overhead of using a function could
> also slow it down.
> >
> >
>
>


Relevant Pages

  • RE: Fulltext failure on a 2 node cluster
    ... Server full-text search resource online: "SQL Cluster Resource 'Full Text' ...
    (microsoft.public.sqlserver.clustering)
  • Re: HELP PLEASE ~ ???
    ... You mentioned that it went ahead and added a SQL ... SQL Server 2000 database for all my data. ... find the connectionString in the newly recreated SQLExpress database. ... The connection string specifies a local Sql Server Express instance ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Multi-Channel Raid VS SAN Storage
    ... A 5~6 years old server is a very old server. ... As I mentioned, the server is one node in a cluster environment, and SQL is ... We actually are running RAID 1+0 and our aplication is definately more ... needs it's own SAN device, or at least a dedicated IO channel on the SAN. ...
    (microsoft.public.sqlserver.setup)
  • Re: Multi-Channel Raid VS SAN Storage
    ... A 5~6 years old server is a very old server. ... As I mentioned, the server is one node in a cluster environment, and SQL is ... We actually are running RAID 1+0 and our aplication is definately more ... needs it's own SAN device, or at least a dedicated IO channel on the SAN. ...
    (microsoft.public.sqlserver.setup)
  • RE: How do I get back to base SQL server on my SBS 2003 server?
    ... After you uninstall SQL 2005, the instance which you upgraded will not go ... Uninstall and then reinstall ISA server. ... Uninstall and then reinstall the Monitoring component. ... Tools to Maintenance, change Monitoring component to Install, and then ...
    (microsoft.public.windows.server.sbs)