In an earlier post, I offered a performance analysis of two equivalent XPath queries. While the results of the analysis are sound, I wish to alert you to a flaw in a portion of my methodology which I learned of today.
The crux of the matter is that the “query costing” functionality in SQL Server Management Studio does not provide reliable results for XQuery on unindexed XML. Rather than relying solely on the query cost numbers in this scenario, you need to look at the full query plan as well as the end-to-end performance of the code.
The original post presents an analysis of the query plans for the two queries which, in this instance, are consistent with the query cost numbers. The conclusions that we reached regarding the relative merits of parent axis access vs. use of the CROSS APPLY operator still hold; we just had a little hole in our validation methodology.