Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

SQL 2005 - SELECT query takes long time to retrieve Expand / Collapse
Author
Message
Posted Tuesday, July 20, 2010 6:58 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 25, 2014 9:34 AM
Points: 389, Visits: 959
SQL 2005 - SELECT query takes long time to retrieve records from a table which has about 250000 records. Even a top 10 takes 4 to 5 mins. Any remedial measures?
Post #955516
Posted Tuesday, July 20, 2010 7:07 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, February 25, 2014 2:26 PM
Points: 386, Visits: 626
When you take a look at the execution plan what do you see?

Twitter: @SQLBalls
Blog: http://www.SQLBalls.com
Post #955524
Posted Tuesday, July 20, 2010 7:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:21 AM
Points: 7,133, Visits: 13,520
balasach82 (7/20/2010)
SQL 2005 - SELECT query takes long time to retrieve records from a table which has about 250000 records. Even a top 10 takes 4 to 5 mins. Any remedial measures?


Not without seeing the query, no. You will get some help if you post the query.
You will get better help if you post the execution plans as already suggested.
For the best help, post the table definition as well, including any indexes, triggers etc along with some sample data.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #955537
Posted Tuesday, July 20, 2010 7:38 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 25, 2014 9:34 AM
Points: 389, Visits: 959
select * from table_name where [time] between
'2009/6/1 6:00am' and '2009/6/30'

no indexes,triggers etc. Field [time] has datatype datetime.
Post #955555
Posted Tuesday, July 20, 2010 7:41 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 5:06 AM
Points: 127, Visits: 1,745
how many columns and rows is there in this table?
if it's a small table it should not take long to display the table at all without indexes on it ...


MCITP: Database Administrator 2005
MCTS DBA 2008
Post #955561
Posted Tuesday, July 20, 2010 7:45 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 25, 2014 9:34 AM
Points: 389, Visits: 959
33 columns and aboutn 250,000 rows.

Execution plan shows Table Scan as 100%. Let me know if any more info is needed
Post #955569
Posted Tuesday, July 20, 2010 7:49 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, February 25, 2014 2:26 PM
Points: 386, Visits: 626
Right click in your query window.

click Include Actual Execution Plan

when you execute the query next there will be an addition info that shows the Graphical query execution plan.

you probably could benefit from a non-clustered index on your date field, or a covering index if the data types are not to large.

here is a good tutorial on query optimization.

http://www.simple-talk.com/sql/performance/execution-plan-basics/


Twitter: @SQLBalls
Blog: http://www.SQLBalls.com
Post #955577
Posted Tuesday, July 20, 2010 7:55 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Friday, July 25, 2014 9:34 AM
Points: 389, Visits: 959
I had created an index the time column.. but since the query took long time to complete, i dropped that index...

As mentioned the Exec plan shows 100% table scan
Post #955585
Posted Tuesday, July 20, 2010 8:01 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, February 25, 2014 2:26 PM
Points: 386, Visits: 626
does the table have a clustered index?

you cannot do a covering index as the limit is 16 columns, I would deffinitally add a clustered and re-create a non clustered on time.


Twitter: @SQLBalls
Blog: http://www.SQLBalls.com
Post #955595
Posted Tuesday, July 20, 2010 8:05 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:03 PM
Points: 42,485, Visits: 35,554
Bradley B (7/20/2010)
you cannot do a covering index as the limit is 16 columns,


The 16 column limit is only on key columns, not on include columns.

balasach, please post table definitions, index definitions and execution plan, as per http://www.sqlservercentral.com/articles/SQLServerCentral/66909/



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #955601
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse