 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server with Mr. Denny &#187; OPENXML</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/sql-server/tag/openxml/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/sql-server</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 17:04:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>OPENXML can be a beast sometimes.</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/openxml-can-be-a-beast-sometimes/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/openxml-can-be-a-beast-sometimes/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 11:00:59 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[OPENXML]]></category>
		<category><![CDATA[Performance Problems]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Table Variables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/?p=765</guid>
		<description><![CDATA[Our application includes some search functionality which is pretty complex to deal with.  In a nutshell the user can select multiple values from a couple of lists on the website and use those listed to filter down the rows which are being searched.  These lists are passed into the SQL Server as a couple of [...]]]></description>
				<content:encoded><![CDATA[<p>Our application includes some search functionality which is pretty complex to deal with.  In a nutshell the user can select multiple values from a couple of lists on the website and use those listed to filter down the rows which are being searched.  These lists are passed into the SQL Server as a couple of XML documents.  We recently had a larger customer call and complain that the search was slow.  I fired up profiler and grabbed the query.  They were right, 6 minutes is a long time for a query to take.<span id="more-765"></span></p>
<p>There&#8217;s some full text searching going on so it&#8217;s never going to really scream as there are 70 million records in one table, 57 million records in another table (with a one to many between them), and another 90 million records in the third table (this is a one to many to the table with 70 million records, and this table has the full text index on it).</p>
<p>Needless to say there was some tuning that I had to do.  The basic jist of the query was&#8230;</p>
<pre class="brush: sql; title: ; notranslate">
...
WHERE EXISTS (SELECT *
FROM OPENXML(@hDoc_Computer, '//computer')
WITH (ComputerId INT '@id') a
WHERE a.ComputerId = Application.ComputerId)
AND EXISTS (SELECT *
FROM OPENXML(@hDoc_Logon, '//login')
WITH (LogonId INT '@id') a
WHERE a.LogonId = Application.LogonId)</pre>
<p>After getting no where working on indexes and tweaking things here and there (and actually making the query take 16 minutes to run for this customer&#8217;s data) I put a couple of table variables in the procedure and loaded those table variables up with the values from the XML Documents.</p>
<pre class="brush: sql; title: ; notranslate">DECLARE @Computer TABLE
(ComputerId INT)

DECLARE @Logon TABLE
(LogonId INT)

...

INSERT INTO @Computer
SELECT ComputerId
FROM OPENXML(@hDoc_Computer, '//Computer', 2)
WITH (ComputerId INT '@ComputerId')

INSERT INTO @Logon
SELECT LogonId
FROM OPENXML(@hDoc_Logon, '//Logon', 2)
WITH (LogonId INT '@LogonId')

...
</pre>
<p>And I changed the WHERE clause to use the table variables instead.</p>
<pre class="brush: sql; title: ; notranslate">WHERE EXISTS (SELECT * FROM @Computer a WHERE a.ComputerId = Application.computerId)
AND EXISTS (SELECT * FROM @Logon a WHERE a.LogonId = Application.LogonId)</pre>
<p>This got my query run time down to about 1 minute with the execution plan showing that ~90% of the time spent is being spent on the full text search. So while I wouldn&#8217;t normally consider a query run time on 1 minute to be good, in this case it is. (This particular part of the application also goes out to the file server and uses Microsoft Search service to search millions of files for text string matches so this is now the fastest part of the search process.</p>
<p>Now don&#8217;t take this post the wrong way. I love OPENXML, it&#8217;s a great tool and I use it all over the place so that we can pass in multiple values in a single variable (all our code has to be able to run on SQL 2005 so table input parameters aren&#8217;t an option for me). OPENXML just wasn&#8217;t the write tool here, sort of.</p>
<p>I wish we could have found this performance problem in QA, but we just have no way to generate enough data to find these kinds of performance problems. But the problem is fixed and the customer is hopefully happy (for now).</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/openxml-can-be-a-beast-sometimes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing XML files with SQL Server functions</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/processing-xml-files-with-sql-server-functions/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/processing-xml-files-with-sql-server-functions/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 21:53:10 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[OPENXML]]></category>
		<category><![CDATA[SearchSQLServer.com]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/?p=439</guid>
		<description><![CDATA[I just published a new article on SearchSQLServer.com called Processing XML files with SQL Server functions. In this article I talk about how to get data from XML files on disk into the SQL Server, and then provide examples on how to use OPENXML to turn the XML data into tabular data so that you [...]]]></description>
				<content:encoded><![CDATA[<p>I just published a new article on <a href="http://www.SearchSQLServer.com" target="_blank">SearchSQLServer.com</a> called<span class="a4"> <a href="http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1347994_mem1,00.html" target="_blank">Processing XML files with SQL Server functions</a>.</span></p>
<p>In this article I talk about how to get data from XML files on disk into the SQL Server, and then provide examples on how to use OPENXML to turn the XML data into tabular data so that you can use it within SQL Server.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/processing-xml-files-with-sql-server-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
