|
To read the follwoing XML i have tried with 4 samples . But when i look at Execution Plan Method 1 is taking 0%? does that mean OPENXML is an optimised one ? pls clarify my doubt ?
(comments are locked)
|
|
Using the nodes method does have the advantage that you don't need to remember to clean up a document handle afterward. Good estimates are almost impossible when XML methods are used, so do not draw any conclusions from these. More generally, estimated costs in query plans are mainly useful internally to the optimizer, and are not intended to be compared between different queries. The fact that SSMS provides a percentage estimated batch cost is extremely misleading to users. OPENXML and nodes() are documented as having very similar performance overall. As far as the specific query is concerned, I find the following form to be more efficient than any of the four in the question:
(comments are locked)
|
|
I totally agree with @Grant Fritchey. Most of the time XQUERY methods especially with filters do offer more optimal performance. In your case, the actual costs in the execution plan with OPENXML are hidden since it involves an outside reference MSXML.dll. Moreover, the cost of preparing and removing the document in case of OPENXML is not reflected there as well, but such kind of cost would have been added for rest of the methods. OPENXML is quite Memory intensive and XQUERY methods tends to be more processor intensive in some cases. So the all popular solution "it depends" would fit here again. But one major drawback with OPENXML is if you have to traverse the table with XML fields, you are left with no other choice but to do it row by row.
(comments are locked)
|
|
Those costs are estimated costs, so you can't use them as measures of performance. Instead, monitor the server using extended events (or trace if you're on 2000) and capture the execution of the queries so you can compare I/O, CPU, and execution time (although execution time is the most variable of the measures, so in order for it to be right you need to take it several times and use the average). That will tell you which is better. In general, the XQuery methods of @foo.nodes is slightly better for performance than OPENXML, but only slightly and not always. That's what I've seen in my performance and with my testing. +1 from here
Jan 18 '12 at 05:06 AM
Usman Butt
+1 for the scary DBA
Jan 18 '12 at 05:27 AM
SQL Kiwi
Ha! And here I gave you a +1.
Jan 18 '12 at 06:27 AM
Grant Fritchey ♦♦
(comments are locked)
|

