Re: Slow query

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Test (no@xxxxxx) writes:
When querying a table with many rows and filtering by a datetime clustered
index (and a couple of other columns), the query is fast in one case and
slow in another. Execution time is 15 seconds the slow way, and 1 second
the fast way.

And a couple of more columns?

If there is one thing I have learnt through the years of working with
SQL Server is that it's meaningless to troubleshoot performance issues
on incomplete information.

Here I can only guess that more columns help to make the query more
selective, so that a non-clustered index can be used. Or the other
way round: in the slow case, the optimizer thinks that a non-clustered
index is a good pick when it isn't. But I can imagine other explanations
as well.

Have you looked at the query plans? They are likely to be different.

If you want us to say something more useful, I would suggest that you
post:
o CREATE TABLE and CREATE INDEX statements for the tables.
o The actual queries.
o The query plans.
o Which version of SQL Server you are using.

As for the query plans, save them from Mgmt Studio (assuming you have
SQL 2005 or later) as .sqlplan files, and attach them. If you are not
available to attach them, put them on web site for download, and post
the URL.

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

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

.



Relevant Pages

  • Re: CONTAINS performance
    ... That said, and with the query plan, I can start to give you more ... relational join in the context of the free-text optimization, ... SQL Server tables. ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Access to SQLServer GCE
    ... Actually, as Larry points out, the Access client does a good job of filtering only information that you need. ... If your query is bound to a report, and you open that report supplying a typical "where" for that report, then Access will NOT pull down all the records, but in most cases Access will only pull down the required records and respect your filter. ... So SQL server will respect the conditions and filtering placed into those queries, and therefore only pull down those records you require. ... The suggestion in these cases is to consider using a pass-through query since all of that summing is done before the row comes down the network pipe. ...
    (comp.databases.ms-access)
  • Re: Indexing Service, Openquery and sp_executesql
    ... SQL Server version and sp are you running? ... > data from the indexing service catalog when pasted into ... > query analyzer, but failed when put against sp_executesql ... I would choose Microsoft Indexing ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Problem using Access or Query Designer to run queries in SQL Serve
    ... >or Query Designer within Enterprise Manager, it works and I get data back. ... >ODBC Call Failed [ODBC SQL Server Driver] Timeout Expirederror in Access ... >[ODBC SQL Server Driver] Timeout Expired ...
    (microsoft.public.sqlserver.odbc)
  • Re: Transaction Isolation Level
    ... This means that while I initiate a transaction selecting all new orders it ... My query is executed on a SQL server 2005. ... the isolation level you should use is snapshot isolation. ...
    (comp.databases.ms-sqlserver)