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

Query taking over 50 mins; Stuff with XML Path Expand / Collapse
Author
Message
Posted Wednesday, October 9, 2013 7:15 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Saturday, May 24, 2014 3:11 PM
Points: 72, Visits: 309
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
Post #1503084
Posted Wednesday, October 9, 2013 7:43 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:23 AM
Points: 13,126, Visits: 11,965
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)
Post #1503108
Posted Wednesday, October 9, 2013 11:36 AM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Yesterday @ 8:06 PM
Points: 36,786, Visits: 31,243
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."

(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 #1503222
Posted Wednesday, October 9, 2013 12:14 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Saturday, May 24, 2014 3:11 PM
Points: 72, Visits: 309
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,'')
Post #1503245
Posted Wednesday, October 9, 2013 12:16 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:23 AM
Points: 13,126, Visits: 11,965
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)
Post #1503246
Posted Wednesday, October 9, 2013 5:00 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Yesterday @ 8:06 PM
Points: 36,786, Visits: 31,243
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."

(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 #1503327
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse