Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


T-SQL Performance tuning on Aggregates


T-SQL Performance tuning on Aggregates

Author
Message
d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52
The below query resulted after 30minutes. It uses 2 uses and SUM().
Attached the execution plan too. Index was created as below. Please help me to tune the performance.

CREATE TABLE #tbl_ChannelViewCost
(
rcc_id NUMERIC(10,0),
activity_dataset_id NUMERIC(10,0),
profit_centre_id NUMERIC(10,0),
channel_dataset_id NUMERIC(10,0),
customer_dataset_id NUMERIC(10,0),
product_category_dataset_id NUMERIC(10,0),
channel_cost NUMERIC(22,8),
driver_id NUMERIC(5,0),
)

CREATE TABLE #tblRCCCommanMOGEValues
(
rcc_id NUMERIC(10,0),
common_cost_rcc_id NUMERIC(10,0),
budget_cost NUMERIC(22,8) DEFAULT 0,
oge_cost NUMERIC(22,8) DEFAULT 0,
globe_cost NUMERIC(22,8) DEFAULT 0,
mge_cost NUMERIC(22,8) DEFAULT 0,
total_cost NUMERIC(22,8) DEFAULT 0,
budget_percentage NUMERIC(22,12) DEFAULT 0,
oge_percentage NUMERIC(22,12) DEFAULT 0,
globe_percentage NUMERIC(22,12) DEFAULT 0,
mge_percentage NUMERIC(22,12) DEFAULT 0,
cc_group TINYINT
)

CREATE TABLE #tblChannelCost
(
profit_centre_id NUMERIC(10,0),
channel_dataset_id NUMERIC(10,0),
customer_dataset_id NUMERIC(10,0),
product_category_dataset_id NUMERIC(10,0),
activity_dataset_id NUMERIC(10,0),
rcc_id NUMERIC(10,0),
driver_id NUMERIC(5,0),
channel_cost_budg NUMERIC(22,8),
channel_cost_oge NUMERIC(22,8),
channel_cost_globe NUMERIC(22,8),
cc_group TINYINT,
common_cost_rcc_id NUMERIC(10,0)
)

#tbl_ChannelViewCost has 3559048 rows.
#tblRCCCommanMOGEValues has 16576 rows. It has pair of rows for the same rcc_id one with 0 in cc_group column and another row has 1 in cc_group column.
Result is stored in #tblChannelCost and has 3410915 rows.

Also, attached the Execution Plan as zip file. Refer the "Query 19" which is related to the query.

CREATE NONCLUSTERED INDEX
idx_tbl_ChannelViewCost_id ON #tbl_ChannelViewCost(profit_centre_id,channel_dataset_id,customer_dataset_id,product_category_dataset_id,activity_dataset_id,rcc_id,driver_id,channel_cost)

CREATE NONCLUSTERED INDEX
idx_tblRCCCommanMOGEValues_rcc_id ON #tblRCCCommanMOGEValues(rcc_id)


Insert into #tblChannelCost
SELECT
c.profit_centre_id,
c.channel_dataset_id,
c.customer_dataset_id,
c.product_category_dataset_id,
c.activity_dataset_id,
c.rcc_id,
c.driver_id,
SUM(c.channel_cost*(r.budget_percentage)) AS channel_cost_budg,
SUM(c.channel_cost*(r.oge_percentage)) AS channel_cost_oge,
SUM(c.channel_cost*(r.globe_percentage)) AS channel_cost_globe,
r.cc_group,
r.common_cost_rcc_id
FROM
#tbl_ChannelViewCost c
INNER JOIN #tblRCCCommanMOGEValues r
ON (
r.rcc_id = c.rcc_id
)
GROUP BY
c.profit_centre_id,
c.channel_dataset_id,
c.customer_dataset_id,
c.product_category_dataset_id,
c.activity_dataset_id,
c.rcc_id,
c.driver_id,
r.cc_group,
r.common_cost_rcc_id
Attachments
Plan4.zip (3 views, 90.00 KB)
kapil_kk
kapil_kk
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2425 Visits: 2763
I think you forget to attach the execution plan....

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52

d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52
Sorry, I don't know why it's not attaching!
I clicked on "Insert Image" icon and typed the local file path and it inserted the html text here. But image is not displaying!
Please provide me the email id so that I can send you.
or Please suggest me few tuning steps for the query without the execution plan!
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16626 Visits: 17024
d_uvarajan (11/8/2013)
Sorry, I don't know why it's not attaching!
I clicked on "Insert Image" icon and typed the local file path and it inserted the html text here. But image is not displaying!
Please provide me the email id so that I can send you.
or Please suggest me few tuning steps for the query without the execution plan!


Don't send a screen shot of the execution plan. That is pretty much useless. Attach the actual file. Gail explained it in your other thread. Right click -> Save Execution Plan As...

Make sure it is the ACTUAL execution plan, not the estimated one.

_______________________________________________________________

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 Moden's 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)
d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52


Attached the execution plan. Please refer "Query 54" in the plan.
If you could not ableto view it, please let me know the steps to upload the same. (I clicked the image icon and provided the the local file path)
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45187 Visits: 39925
d_uvarajan (11/9/2013)


Attached the execution plan. Please refer "Query 54" in the plan.
If you could not ableto view it, please let me know the steps to upload the same. (I clicked the image icon and provided the the local file path)


An image of the execution plan will do us no good. Please see the 2nd link under "Helpful Links" in my signature line below on how to post a performance problem to get the best help.

Also, is the rcc_id a UNIQUE column in the #tblRCCCommanMOGEValues table?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52
Thank you for providing me the link.

I have updated the post with more detail with respect to Tables definition, execution plan etc., The RCC_Id in #tblRCCCommanMOGEValues is not Unique and there will 2 rows for each Rcc_id in the table #tblRCCCommanMOGEValues. One row will have 0 for its cc_group column and another will have 1 for the cc_group column.

Please let me know if you require any more details.
GilaMonster
GilaMonster
SSC-Forever
SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)SSC-Forever (47K reputation)

Group: General Forum Members
Points: 47299 Visits: 44392
d_uvarajan (11/9/2013)
Attached the execution plan. Please refer "Query 54" in the plan.


Query 54 is 0% of the cost of the batch. Why do you think it's the problem?

Can you go through that procedure (as described in the article Jeff referenced), identify exactly which queries are the problems and upload the plans of just those queries. It will involve running them one by one.

Also, we need an actual plan (as the article explains), not an estimated plan. You attached an estimated plan.


Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


d_uvarajan
d_uvarajan
SSC-Enthusiastic
SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)SSC-Enthusiastic (156 reputation)

Group: General Forum Members
Points: 156 Visits: 52
Thanks. As requested attached the "Actual Execution Plan". Now it shows Query cost 75%.
Refer the "Query 19" which is related to the query.
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