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»»

T-SQL Performance tuning on Aggregates Expand / Collapse
Author
Message
Posted Friday, November 8, 2013 6:49 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50
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


  Post Attachments 
Plan4.zip (3 views, 90.10 KB)
Post #1512648
Posted Friday, November 8, 2013 7:11 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 9, 2014 3:27 AM
Points: 1,893, Visits: 2,329
I think you forget to attach the execution plan....


_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1512660
Posted Friday, November 8, 2013 7:21 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50
Post #1512666
Posted Friday, November 8, 2013 7:24 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50
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!
Post #1512672
Posted Friday, November 8, 2013 8:07 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 8:30 AM
Points: 12,939, Visits: 12,351
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)
Post #1512695
Posted Saturday, November 9, 2013 12:11 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50


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)
Post #1512885
Posted Saturday, November 9, 2013 1:50 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:36 AM
Points: 35,218, Visits: 31,677
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1512928
Posted Monday, November 11, 2013 12:59 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50
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.
Post #1513015
Posted Monday, November 11, 2013 1:13 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:32 AM
Points: 39,905, Visits: 36,245
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 2008, MVP
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

Post #1513016
Posted Monday, November 11, 2013 4:10 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, January 30, 2014 5:53 AM
Points: 108, Visits: 50
Thanks. As requested attached the "Actual Execution Plan". Now it shows Query cost 75%.
Refer the "Query 19" which is related to the query.
Post #1513061
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse