Re: Very slow query

From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 17:47:52 +0200

The very first thing to do is consider what indexes you have on the table. Indexing is a huge topic,
with lots if information in Books Online, Books, Courses, the Net etc. But for this particular
situation, a COUNT(*) will benefit very much from a nonclustered index on any column, preferable a
small column (like int etc).

While testing the query in QA, use the "Show Estimated Query Plan" feature. It will show how the
query will be executed.

This is what I suggest you also pick up using Profiler. Profiler is a tracing tool, and you find it
in the SQL Server program group. It is also useful to, for instance, catch the actual SQL
statements. Sometime, your API (ADO in your case) as doing funny things for you...

-- 
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Steve" <sedmyer@indy.rr.com> wrote in message news:Sdadd.106317$V06.10636@fe2.columbus.rr.com...
> Tibor,
>
> I am a VB programmer and have little experience with SQL Server (from a DBA perspective).
>
> First I think that the time taken by QA to run this query is way to long and would like to know if 
> I am doing something wrong or if there is something that can be done to the DB to improve.
>
> Second how do I start and use this Profiler?
>
> Thanks
> Steve
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in message 
> news:uxCDi6etEHA.2624@TK2MSFTNGP11.phx.gbl...
>>I would start using Profiler to see if the two has the same execution plan.
>>
>> -- 
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>>
>>
>> "Steve" <sedmyer@indy.rr.com> wrote in message news:TA9dd.3580$Dl.236@fe1.columbus.rr.com...
>>> Any ideas as to why a simple query (SELECT COUNT(*) FROM Table) on a table with 1,900,000 rows 
>>> would take 3 minutes to run in Query Analyzer and more than 10 minutes to run from a VB 6 app 
>>> using ADO?
>>>
>>
>>
>
> 


Relevant Pages

  • Re: Database Engine Tuning Advisor suggestion to replace syntax.
    ... What you said was what I first planned to say, but then I read the Books Online which implies that the batch is indeed reused, so I held back from saying that. ... the query optimizer will probably match the Transact-SQL statement in the second execution with the execution plan generated for the first execution. ... SQL Server does not have to compile the second statement." ...
    (microsoft.public.sqlserver.tools)
  • Re: Many to one Select
    ... It still possible to define a query that has maximum of columns needed, ... INSERT statements with sample data. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: timezones in select statement
    ... > end, in the sense that I don't want it to be pulled back in the query, ... INSERT statements with sample data. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: UPDATE query gives Incorrect Syntax error
    ... Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books ... ... No - no triggers on the table. ... Is it possible that a previous query has somehow become trapped and is ...
    (comp.databases.ms-sqlserver)
  • Re: server-side profiling
    ... Although rows are stored in tables in SQL Server, ... of a query, rows are retreived from these on-disk 8kb pages but a caching ... The Reads column in the Profiler displays LOGICAL reads. ... Duration and Reads are commonly monitored together because they can both be ...
    (microsoft.public.sqlserver.server)