Long Query Time

Long Query Time

Post by Jay Sing » Thu, 08 Jun 2000 04:00:00



I have a table with 2.6 million records against which I am performing
the following query and it is taking 13.28 minutes

Is it normal or is this really long time. The Server is dual pentium
with 1 GB RAM

SELECT UserName, app, sum(datediff(minute, Start_time, end_time)) as
Usage
FROM trackapp
WHERE start_time > '5/1/2000' and end_time < '5/30/2000'
AND   app_path not like 'c:\%'
GROUP BY UserName, app
ORDER BY UserName.

I have following indexes defined:
1) trackapp ;Clustered ; Located on Primary; Process_ID, Start_time,
WServer
2) TRACKAPP3 ; NON CLUSTERED; Located on Primary; Wserver
3) TRACKAPP4 ; NON CLUSTERED; Located on Primary; App
4) TRACKAPP5 ; NON CLUSTERED; Located on Primary; App_Path
5) TRACKAPP6 ; NON CLUSTERED; Located on Primary; WDomain, UserName
6) TRACKAPP7 ; NON CLUSTERED; Located on Primary; Star_Time, End_time,
App_Path

Examination of the Query Plan shows that it is doing a Clustered Index
Scan.

I have also run the Update Statistics on all indexes but no change in
execution time.

Any help or guidance would be greatly appreciated.

Thanks
Jay

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Long Query Time

Post by David K. Brow » Thu, 08 Jun 2000 04:00:00


Quote:> Examination of the Query Plan shows that it is doing a Clustered Index
> Scan.

A clustered index scan is the same thing as a table scan.  So, you are not
using an index in your query.  This could explain why you are taking 13
minutes to complete the query.

Dave Brown

 
 
 

Long Query Time

Post by Tibor Karasz » Fri, 09 Jun 2000 04:00:00


So, depending on the selectivity of the query, you might want to create an index on
the column used in the WHERE clause (the date columns).

--
Tibor Karaszi, SQL Server MVP
Please reply to the newsgroup only, not by email.



Quote:> > Examination of the Query Plan shows that it is doing a Clustered Index
> > Scan.

> A clustered index scan is the same thing as a table scan.  So, you are not
> using an index in your query.  This could explain why you are taking 13
> minutes to complete the query.

> Dave Brown

 
 
 

Long Query Time

Post by Jay Sing » Fri, 09 Jun 2000 04:00:00


I tried creating another index, however it seems that the query refuses
to utilize any other index other than Clustered Index Scan. I then
transfered the table onto another server, in this case on the other
machine the query used the index that I created and not the clustered
index scan.

It appears that the query execution plan is cached and the engine
refuses to acknowledge the presence of another index that is more
suitable.

How do I make the engine acknowledge the other index. I have already
run the update stats.

Thanks Jay



> So, depending on the selectivity of the query, you might want to
create an index on
> the column used in the WHERE clause (the date columns).

> --
> Tibor Karaszi, SQL Server MVP
> Please reply to the newsgroup only, not by email.



> > > Examination of the Query Plan shows that it is doing a Clustered
Index
> > > Scan.

> > A clustered index scan is the same thing as a table scan.  So, you
are not
> > using an index in your query.  This could explain why you are
taking 13
> > minutes to complete the query.

> > Dave Brown

Sent via Deja.com http://www.deja.com/
Before you buy.
 
 
 

Long Query Time

Post by Keith Kratochvi » Fri, 09 Jun 2000 04:00:00


Jay, you could
drop and recreate the stored procedure
stop and start SQL Server
exec sp_recompile 'tablename'
exec sp_recompile 'stored procedure name'
dbcc freeproccache (I think that this is only available on 7.0)

Keith


> I tried creating another index, however it seems that the query refuses
> to utilize any other index other than Clustered Index Scan. I then
> transfered the table onto another server, in this case on the other
> machine the query used the index that I created and not the clustered
> index scan.

> It appears that the query execution plan is cached and the engine
> refuses to acknowledge the presence of another index that is more
> suitable.

> How do I make the engine acknowledge the other index. I have already
> run the update stats.

> Thanks Jay



> > So, depending on the selectivity of the query, you might want to
> create an index on
> > the column used in the WHERE clause (the date columns).

> > --
> > Tibor Karaszi, SQL Server MVP
> > Please reply to the newsgroup only, not by email.



> > > > Examination of the Query Plan shows that it is doing a Clustered
> Index
> > > > Scan.

> > > A clustered index scan is the same thing as a table scan.  So, you
> are not
> > > using an index in your query.  This could explain why you are
> taking 13
> > > minutes to complete the query.

> > > Dave Brown

> Sent via Deja.com http://www.deja.com/
> Before you buy.

 
 
 

Long Query Time

Post by SJ » Sat, 22 Jul 2000 04:00:00


Other than recompiling the stored proc, you can user optimizer
hints in your query to specify the index you want the query to
use.  Got to books online, and search for "hints" or "optimizer
hints", and you'll see the title "hints" in the topic list.

-----------------------------------------------------------

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com

 
 
 

1. Query takes 60 times longer than it used to take

Hi all,
I feel Murphy's roaming arround again.

I have a simple select query which uses a secondary index, used to
take a few miliseconds until this morning, now takes 4 seconds and
makes awfully lots of I/O's on the disk where that index is, although
it knows that it should only retreive one single page. (As in the QEP
below).
It was OK until this morning, then SUDDENLY it slowed down. The index
still remains and there doesn't seem to be any problem on the disk
etc. No errors on errlog. Index still remains (otherwise the query
should've been taking hours, becouse there are over 60 million rows on
the table).

I would think that the maintanence is bad, if it takes long but still
retreives one page (although it's hard to beleive that the maintanence
got worse so suddenly). But It seems it's trying to retreive the whole
index rather than a single page.

Does anybody have an idea why this is happening?

(IngresII 2.02 over OpenVMS 7.2 1H1)

Regards,
Ozgul Yavuz

  1> set qep

  2> select count(acce_msn)from acce_accessory
             where acce_manufacturer='PREPAID' and acce_serial_number=
           '801138500'

********************************************************************

QUERY PLAN 3,2, no timeout, of simple aggregate

    aggregate expression ->
count
(acce_msn)

                        T Join(tidp)

                        Heap                      
                        Pages 1 Tups 1

                        D6 C0

             /                      \

            Proj-rest               acce_accessory

            Heap                    B-Tree(NU)

            Pages 1 Tups 1          Pages 2145163 Tups 60669536

            D5 C0

 /

idx_acce_serial

I(acce_accessory)

B-Tree(acce_serial_number,              

 acce_manufacturer)

Pages 1311085 Tups 60669536

********************************************************************

col1    
    0

(1 row)
End of Request

2. PDOX7-WIN95 GPF's

3. Query analyzer results take longer the first time

4. A few questions about VB5 and Access

5. Query taking a long time...

6. Program using ODBC hangs for awhile...

7. Query Taking a Long Time

8. Help needed with expression

9. sql query taking a long time

10. Server times out because of long-running query

11. Nested subquery and long query execution time

12. Informix Query takes 10 times longer than Orrible

13. Query takes a long time