Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Slow select statement

Author  Topic 

igerasimov
Starting Member

2 Posts

Posted - 2011-05-16 : 13:01:05
I have two tables with 5,000,000 rows in each and try to run select statement:
select
c.item_number
,c.lead_storenumber
,r.retail_qty
,r.retail_prc
,r.ao_code
,r.cat_num
from dbo.stg_cst_adsi c
join dbo.stg_rtl_adsi r on (c.item_number = r.item_num
and c.lead_storenumber = r.lead_store)
where c.extract_period='201212'

I created clustered combined indexes for c.item_number,
c. lead_storenumber and r.item_num,r.lead_store.

This statement run 7 hours to complete. This is unacceptable. Can you help me to resolve this problem?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-05-16 : 13:33:48
7 hours means that query performance is not your (only) problem. There must be other things going on. Does it take seven hours in a query window? Or are you trying to load an application or page with results?

If it is NOT a query window then try it there first. If it is fast then you know your problem is outside the database.

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-05-16 : 13:39:02
what is your row count?

And WHAT do you expect to do with the result set if it is around 5 million rows?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-05-16 : 14:16:31
You need an index on c.extract_period.

How many rows does the query return? Is there any blocking? What does the execution plan show?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -