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


Query Optimization help


Query Optimization help

Author
Message
- Win
- Win
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 625
I am trying to optimize one query which runs in SSIS package.
I ran db tuning advisor as well, it recommended 2 non clustered indexes and 7 create statistics for that query.

Issue: it runs sometime fine and gives results in 1.25 mins.
sometimes it runs for hours and hours. else I will kill the process and again re-run.
I see when db log backup or differential runs, it goes to suspended status. at that time we kill the process and wait until the job
completes, and rerun.
I also verified that this query was created 3 yrs ago and I am not much that familiar with tuning queries.

I see the CPU utilization increases high and DiskIO also increases high when this SSIS package runs.

Can anyone desperately help me in tuning the query.
Please find the attached.

Cheers,
- Win
"Dont Judge a Book by its Cover"
Attachments
DB_DOLBY_ALLOC_Query.txt (53 views, 8.00 KB)
John Mitchell-245523
John Mitchell-245523
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14037 Visits: 15946
If you don't have much experience of tuning queries, then I would advise you to seek advice from someone does. You'll need to pay for that if you don't have anyone in your organisation. If you post the Actual execution plan, we can take a look and point out anything that's obvious, but we can't see your table definitions or data and therefore it's difficult for us to offer anything other than general suggestions.

John
- Win
- Win
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 625
Thanks for your reply.

I tuned it to better than earlier, since earlier query was bit critical with joins.
But I am not that much proficient to minimize the query and tune it.
I created the recommended Index, but now its in Index scan.

Please find the attached execution plan and suggest me.

Cheers,
- Win
"Dont Judge a Book by its Cover"
Sean Pearce
Sean Pearce
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1766 Visits: 3432
As John mentioned, we need the Actual execution plan and not the estimated plan. I also suggest not using NOLOCK everywhere.



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
- Win
- Win
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 625
Thanks for your response.
As per the logic we need to fetch full data from tables.
I modified the script using temp tables in it is working as expected, normal run as of now.

Cheers,
- Win
"Dont Judge a Book by its Cover"
- Win
- Win
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 625
Please find the actual execution plan.
Please let me know for any recommendations and modifications in the query as posted earlier.

The logic is, we need to pull complete data from a table XXIST, where it fetches 70 billions of records every run (scheduled).

Awaiting for responses.

Have great times..

Cheers,
- Win
"Dont Judge a Book by its Cover"
- Win
- Win
SSC Veteran
SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)SSC Veteran (238 reputation)

Group: General Forum Members
Points: 238 Visits: 625
Any help is appreciated.

Cheers,
- Win
"Dont Judge a Book by its Cover"
Sean Pearce
Sean Pearce
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1766 Visits: 3432
There are a number of performance issues here. I would quote a client 2 days minimum to optimize this one. However what did jump out at me was the excessive lookups from [DB_Staging].[dbo].[EXCPTRNSPF] due to a poor estimation. Make sure stats are up to date on [EXCPTRNSPF].



You might see decent improvements if you can make [idx_EXCPTRNSPF_i_nc_02] covering by including LOBCODE.



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Attachments
Lookups.png (158 views, 11.00 KB)
Sean Pearce
Sean Pearce
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1766 Visits: 3432
[JOKE]
What's in tbl_gods_lineOfBusiness. Does the query only run on Sunday's?
[/JOKE]



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25954 Visits: 17519
One other thing is you might want to read up on NOLOCK. You have it littered all over this query. That hint is not a magic go fast solution. It is fraught with a number of very real and possible negative impacts. It can and will return duplicate and/or missing rows which can be nearly impossible to recreate on demand. Please read up and understand what that hint does.

http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx

http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

http://www.jasonstrate.com/2012/06/the-side-effect-of-nolock/

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
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