I’m still struggling with learning XQuery. My latest little revelation was small, but vital.
The difference between:
@inXML.nodes('/rss/channel/item')
and
@inXML.nodes('/rss[1]/channel[1]/item')
Is the difference between a 10 minute query and a 4 second query. Kind of shocking really. My understanding is that XQuery assumes there are multiple possible paths that look like “/rss/channel” so it searches over and over again through the XML to see if it can find them. But by identifying it as a root, showing that only one possible path is available, it stops stumbling around in the dark and simply reads the data.
It’s a little thing, but it made an enormous difference. I’ve still got a long way to go in learning how to use XPath within XQuery.
UPDATED: I modified the title so that it’s clear I’m talking about SQL Server here.