July 20, 2010 at 6:58 am
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?
July 20, 2010 at 7:07 am
When you take a look at the execution plan what do you see?
Twitter: @SQLBalls
Blog: http://www.SQLBalls.com
Channel: https://www.youtube.com/@Tales-from-the-Field
July 20, 2010 at 7:19 am
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.
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
July 20, 2010 at 7:38 am
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.
July 20, 2010 at 7:41 am
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 SQL Server 2008
MCP SQL 2012/2014
MCSA SQL Server 2012/2014
MCSE Data Management and Analytics
July 20, 2010 at 7:45 am
33 columns and aboutn 250,000 rows.
Execution plan shows Table Scan as 100%. Let me know if any more info is needed
July 20, 2010 at 7:49 am
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
Channel: https://www.youtube.com/@Tales-from-the-Field
July 20, 2010 at 7:55 am
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
July 20, 2010 at 8:01 am
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
Channel: https://www.youtube.com/@Tales-from-the-Field
July 20, 2010 at 8:05 am
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, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 20, 2010 at 8:59 am
Learn something new every day....and man there is a lot to learn.
the limit on include columns is 1023.
http://msdn.microsoft.com/en-us/library/ms190806.aspx
I stand corrected, when you remake the non clustered index I would make it a covering index over the select statement.
But 1st I'd do what Gail had suggested.
Twitter: @SQLBalls
Blog: http://www.SQLBalls.com
Channel: https://www.youtube.com/@Tales-from-the-Field
January 9, 2013 at 11:29 pm
Create a non clustered index on the field [Time] and then execute the query again.
You should have a clustered index on the table also.
January 10, 2013 at 12:03 am
Please note: 2 year old thread.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 10, 2013 at 1:00 pm
Thanks Roopesh,
As Gail said, been long time since i posted the issue. I resolved it, but dont rememeber how i did it then. In any case, will remember all the options posted in this thread for future.
IMHO, i think such replies to older posts, would be helpful to some other lost souls (even if the original person who posted stopped following the thread).
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply