SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Suggestions / comments required on a query


Suggestions / comments required on a query

Author
Message
T.Ashish
T.Ashish
SSC Eights!
SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)SSC Eights! (913 reputation)

Group: General Forum Members
Points: 913 Visits: 599
Hi all,

I have pasted a query below and I need your suggestions or comments on same. Is there any improvement possible in it?
Execution plan is attached.


SELECT
wl.work_location_id,
isnull(wld.name, wl.name) + ' (' + wl.code + ')' AS name
FROM
dbo.work_location wl(nolock)
LEFT JOIN site s(nolock) on wl.site_id = s.site_id
AND wl.buyer_code = s.buyer_code
LEFT JOIN dbo.work_location_locale wld(nolock) on wl.work_location_id = wld.work_location_id
AND wld.locale = NULL
WHERE
((wl.site_id IN (
SELECT
site_id
FROM
dbo.person_site ps(nolock)
WHERE
ps.person_id = 'z12080916195260579617a66'
)) OR EXISTS (
SELECT
'x'
FROM
dbo.person(nolock)
WHERE
(role_id = '5')
AND person_id = 'z12080916195260579617a66'
))
AND wl.buyer_code = 'FNMA'
AND wl.site_id = 'z12080916474848364992a66'
AND wl.active_flag = 1
AND (NOT EXISTS (
SELECT
1
FROM
dbo.company_config cc(nolock)
WHERE
cc.company_code = '1037'
AND cc.config_id IN (2002)
AND cc.enabled_flag = 1
) OR EXISTS (
SELECT
1
FROM
dbo.person_division_code pdc(nolock)
WHERE
pdc.person_id = 'z12080916195260579617a66'
AND pdc.division_code_id = s.division_code_id
))
Attachments
Query.txt (8 views, 1.00 KB)
plan.sqlplan (9 views, 75.00 KB)
Eugene Elutin
Eugene Elutin
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5086 Visits: 5478
For a start you better to do following two things:

1. Format your query into more readable form - use indent, otherwise code looks like noodles.
2. Remove NOLOCK hints (http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/16/1345.aspx)

_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40927 Visits: 32666
Except for the key lookup, nothing jumped out at me. You can try to eliminate that by including the columns needed to satisfy the query in the nonclustered index.

Nothing else lept out as a major issue.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18907 Visits: 20460
.. use indent, otherwise code looks like noodles.
Hehe


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search