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
 General SQL Server Forums
 New to SQL Server Programming
 I need some index help

Author  Topic 

craigwg
Posting Yak Master

154 Posts

Posted - 2012-03-23 : 12:26:51
I have a query that is running so slow its crashing the application in which it runs. I have been trying to methodically apply indexes but I'm getting nowhere. I realize I may need to rebuild some indexes but can someone help me with which indexes I need to build? This is something I have always struggled with! Here is the query:


select standardid, rq.requirementid, rq.requirementName, policy_Name, count(*)
FROM Policy..rpt_controlRegion_primaryMetrics rcr
INNER JOIN Policy..xref_regionSubs xrs ON rcr.regionId = xrs.regionid
INNER JOIN Policy..vw_autoFail_bySubsidiary afs ON xrs.subsidiaryId = afs.subsidiaryId
INNER JOIN Policy..rpt_standardRegionControl src ON rcr.controlId = src.controlId AND rcr.regionId = src.regionId
INNER JOIN Policy..rpt_policyRegionControl prc ON rcr.controlId = prc.controlId AND rcr.regionId = prc.regionId
INNER JOIN Policy..vw_Policies p ON prc.policyid = p.policyId
INNER JOIN Policy..xref_requirementPolicy xrp on p.policyId = xrp.policyId and xrp.deleted<>1
INNER JOIN Policy..vw_requirements rq on xrp.requirementId = rq.requirementId and rq.active=1
group by standardid, rq.requirementid, rq.requirementName, policy_Name


I have been looking at sys.dm_db_missing_index_details and I've built those indexes all ready. In fact running a select * from sys.dm_db_missing_index_details brings up NO suggested indexes.

Craig Greenwood

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-23 : 12:59:07
I don't thing you're going to find indexes to help that. Indexes help the most with filtering resultsets. You're not doing any major filtering there, that query is reading the entire of a whole bunch of tables.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-03-23 : 13:05:47
What version of SQL are you using?

You *might* be able to gain something by using filtered indexes on the tables where you checking for active = 1. Also is it possible to rewrite the deleted <> 1 to a non-negative check? Like deleted = 0? If so, then you might get some gain from a filtered index.
Go to Top of Page
   

- Advertisement -