Register
Sunday, February 05, 2012
 
 DBAs And ProgrammersBlog
  
News! Minimize
   
 
 Print   
 
Misc Blog Stuff Minimize
   
 
 Print   
 
The Reluctant DBA Minimize
 
 
 
 Print   
 
Reluctant DBA Minimize
   
 
  
 
Reluctant DBA Minimize
   
 
  
 
The Reluctant DBA Minimize
 
May9

Written by:CarpDeus
5/9/2008 1:33 PM 

I ran into something interesting and I'm not really sure what happened.

Code that has been running with no problem suddenly started to have performance impacts. When I took a look at the query's execution plan, I found that the expenses were all with a chunk of XML.  This stored procedure called another one (code reuse is good) that returned XML. I then queried that XML block a couple of times using variations on:

SELECT Tbl.Col.value('MediaID[1]', 'bigint'),Tbl.Col.value('FolderPath[1]', 'nvarchar(2048)') FROM  @MediaListXML.nodes('//assets') Tbl(Col)

For some reason, this took a long time to process, even with only three simple items in the XML. By changing the code to store the relevant columns in a table variable:

DECLARE @MediaList table(MediaID bigint,FolderPath nvarchar(2048))
INSERT INTO @MediaList select Tbl.Col.value('MediaID[1]', 'bigint'),Tbl.Col.value('FolderPath[1]', 'nvarchar(2048)')
          FROM  @MediaListXML.nodes('//assets') Tbl(Col)

For whatever reason, replacing the multiple queries of the XML that had been performing perfectly fine for months before this with the table variable took the request from 34+ seconds down to less than 1.

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment  Cancel 
 
 
  
 
Privacy Statement | Terms Of Use Copyright 2001-2008 by ReluctantDBA.com