I am doing some rough tests with the SQL Server 2008 XML type. I have seen many places where .exist used in where clauses. I recently compared two queries and got odd results.
select count(testxmlrid) from testxml where Attributes.exist('(form/fields/field)[@id="1"]')=1
This query takes about 1.5 seconds to run, without indexes on anything but the primary key (testxmlrid)
select count(testxmlrid) from testxml where Attributes.value('(/form/fields/field/@id)[1]','integer')=1
This request, on the other hand, takes about 0.75 seconds to run.
I use untyped XML, and my benchmarking happens on an instance of SQL Server 2008 Express. There are about 15,000 rows in the dataset, and each XML row is about 25 rows long.
Are these results correct? If so, why is everyone using .exist ? Am I doing something wrong, can an .exist be faster?
Earlz source share