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


Query taking over 50 mins; Stuff with XML Path


Query taking over 50 mins; Stuff with XML Path

Author
Message
Eshika
Eshika
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 314
Hi I am using Stuff with XML Path for concatenating the data in multiple columns like city, town etc by Zip code. ie., unique column is Zip and all the cities will be concatenated to one cell, similarly town and so on. The query runs over 1 million data, table has 180 columns.

I tried -
Adding indexes to the table, it took 50 minutes to run the query.
Added a temporary table to get only required 20 columns and added indexes to the temporary table and it helped reduce about 3 minutes.

Checked the execution plan the issue was with the table scan. There are no filters required to generate this report.

Can you please suggest what else could be done to improve.

Thanks
Esha
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: 16576 Visits: 17020
Eshika (10/9/2013)
Hi I am using Stuff with XML Path for concatenating the data in multiple columns like city, town etc by Zip code. ie., unique column is Zip and all the cities will be concatenated to one cell, similarly town and so on. The query runs over 1 million data, table has 180 columns.

I tried -
Adding indexes to the table, it took 50 minutes to run the query.
Added a temporary table to get only required 20 columns and added indexes to the temporary table and it helped reduce about 3 minutes.

Checked the execution plan the issue was with the table scan. There are no filters required to generate this report.

Can you please suggest what else could be done to improve.

Thanks
Esha


We need a LOT more details to offer much help. We would need to see the table with index definitions. The query you are running and the actual execution plan at a bare minimum.

How to post Performance Problems

_______________________________________________________________

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)
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: 45119 Visits: 39918
Eshika (10/9/2013)
Hi I am using Stuff with XML Path for concatenating the data in multiple columns like city, town etc by Zip code. ie., unique column is Zip and all the cities will be concatenated to one cell, similarly town and so on. The query runs over 1 million data, table has 180 columns.

I tried -
Adding indexes to the table, it took 50 minutes to run the query.
Added a temporary table to get only required 20 columns and added indexes to the temporary table and it helped reduce about 3 minutes.

Checked the execution plan the issue was with the table scan. There are no filters required to generate this report.

Can you please suggest what else could be done to improve.

Thanks
Esha


Please see the second link in my signature line below under "Helpful Links".

--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
Eshika
Eshika
Valued Member
Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)Valued Member (74 reputation)

Group: General Forum Members
Points: 74 Visits: 314
Bellow is the code:

-- getting required columns to a temporary table
SELECT LTRIM(RTRIM(Zip)) Zip, Code ,LTRIM(RTRIM(City)) CLLI, LTRIM(RTRIM(City)) CLLI,LTRIM(RTRIM(State)) State,Processed ,LTRIM(RTRIM(A))[A],LTRIM(RTRIM([B]))[B]
,LTRIM(RTRIM([C]))[C],LTRIM(RTRIM([D]))[D],LTRIM(RTRIM([E]))[E],LTRIM(RTRIM([F]))[F],LTRIM(RTRIM([G]))[G],LTRIM(RTRIM(H))H ,LTRIM(RTRIM(I)) I
INTO #IMS_StgTemp FROM IMS_StgUpload WHERE (Processed IS NULL OR Processed ='D')

CREATE NONCLUSTERED INDEX [IDXRT] ON #IMS_ StgTemp
(
[Zip] ASC,
City ASC,
[A] ASC,
[B] ASC,
[C] ASC,
[D] ASC,
[E] ASC,
[F] ASC,
[G] ASC,
[H] ASC,
[I] ASC,
[State] ASC,
[Processed] ASC,
[Code] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO

INSERT INTO #REPORT_ZIP (Zip, Code,State, Totals)
SELECT LTRIM(RTRIM(Zip)), ISNULL(Code,'') LEAD_OWNER, ISNULL( LTRIM(RTRIM(State)),'') STATE, count(*)
FROM #IMS_ StgTemp
WHERE (Processed IS NULL OR Processed ='D')
GROUP BY LTRIM(RTRIM(Zip)) , ISNULL(Code,''), ISNULL(LTRIM(RTRIM(State)),'')
ORDER BY LTRIM(RTRIM(Zip)) , ISNULL(Code,''), ISNULL(LTRIM(RTRIM(State)),'')

UPDATE t
SET t.CLITY= C.CityList
, t.Town= C.townList
,t.SharedBy =C.SharedOwnerList
, t.I = C.I
FROM #B2BICLREPORT_ZIP t INNER JOIN
(SELECT p.zip, ISNULL(p.OfficeCode,'')OfficeCode
,stuff((SELECT DISTINCT ', ' + LTRIM(RTRIM(CLLI)) FROM #IMS_StgB2BLeadsUpload LC
where (Processed IS NULL OR Processed ='DINP') AND LTRIM(RTRIM(LC. Zip)) = p.Zip
and ISNULL(LC. Code,'') = ISNULL(p.Code,'') for xml path('')),1,2,'') as ClliList

,stuff((SELECT DISTINCT ', ' + LTRIM(RTRIM(City)) FROM #IMS_StgB2BLeadsUpload LC
where (Processed IS NULL OR Processed ='DINP') and LTRIM(RTRIM(LC.Zip)) = p.Zip
and ISNULL(LC. Code,'') = ISNULL(p.Code,'') for xml path('')),1,2,'') as CityiList

,stuff((SELECT DISTINCT ', ' + LTRIM(RTRIM(Code)) FROM #IMS_StgB2BLeadsUpload LC
where (Processed IS NULL OR Processed ='DINP') and LTRIM(RTRIM(LC. Zip)) = p.Zip
and ISNULL(LC. Code,'') != ISNULL(p. Code,'') for xml path('')),1,2,'') as SharedOwnerList

, (select count(*) FROM #IMS_StgB2BLeadsUpload LC
where (Processed IS NULL OR Processed ='DINP') and LTRIM(RTRIM(LC.SrvcZip)) = p.Zip
and ISNULL(LC. Code,'') != ISNULL(p. Code,'')) I
FROM #B2BICLREPORT_ZIP p
GROUP BY p.Zip, ISNULL(p.Code,''),CLLI, City, Code) C
ON C. Zip = t.Zip and C. Code = ISNULL(t.Code,'')
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: 16576 Visits: 17020
Again, without table definitions, indexes and an actual execution plan we are shooting in the dark. Both Jeff and I have suggested you read the article about how to post performance problems. Without that information we can't provide informed assistance.

_______________________________________________________________

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)
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: 45119 Visits: 39918
Eshika (10/9/2013)
Bellow is the code:


I think maybe not. The "C" derived table doesn't have the "townlist" column that have you in the update list. Also, why are you calculating a "ClliList" when it's not being used anywhere and that same thing goes for the two temp tables you create... they're also not being used anywhere.

Please help us help you. Read the article that you've been directed to.

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