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

Query running slow on prod. Expand / Collapse
Author
Message
Posted Monday, June 17, 2013 11:20 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, September 15, 2014 3:25 AM
Points: 718, Visits: 547
this is the actual plan from prod server.

  Post Attachments 
query.sqlplan (5 views, 123.86 KB)
Post #1464457
Posted Tuesday, June 18, 2013 1:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:44 AM
Points: 6,719, Visits: 13,828
T.Ashish (6/17/2013)
this is the actual plan from prod server.


Thanks for posting.
I'd recommend you implement the indexes I posted earlier and repost the actual plan from prod with the indexes in place. Taken in isolation from all other queries against these tables, they are fine and should give you at least an order of magnitude lift in performance for this query: however, you should examine index usage stats and query activity (most frequent/most expensive) and tweak if necessary.

Here's a slightly modified version of the query you ran in prod. I've removed the eccentric and offputting formatting and corrected a filter in the os_contract subquery:

DECLARE @0 BIT, @1 INT
SELECT @0 = 1, @1 = 2

SELECT
activity_flag = case when c.activity_flag = 1 then 'Active' else 'Inactive' end,
msp_flag = case when bsc.msp_flag = 1 then 'true' else 'false' end,
c.name,
c.comp_code,
p.active_users,
p.new_users,
p.inactive_users,
w.worker,
c.test_comp_flag,
c.parent_comp_flag
FROM dbo.comp c ( NOLOCK )

LEFT JOIN (
SELECT
comp_code,
active_users = SUM(case when activity_flag = 1 and reg_flag = 0 then 1 else 0 end),
new_users = SUM(case when activity_flag = 1 and reg_flag = 1 then 1 else 0 end),
inactive_users = SUM(case when activity_flag = 0 then 1 else 0 end)
FROM dbo.person
GROUP BY comp_code
) p
ON p.comp_code = c.comp_code

LEFT JOIN (
SELECT
COUNT(*) worker,
owner_code
FROM dbo.worker
GROUP BY owner_code
) w
ON w.owner_code = c.comp_code

LEFT JOIN (
SELECT
msp_flag,
owner_code
FROM dbo.os_contract
WHERE msp_flag = @0
GROUP BY msp_flag, owner_code
) bsc
ON bsc.owner_code = c.comp_code
--and bsc . msp_flag = @0

WHERE c.comp_type = @1
ORDER BY c.name




“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 #1464480
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse