I am doing some crude benchmarks with the xml datatype of SQL Server 2008. I've seen many places where .exist
is used in where
clauses. I recently compared two queries though 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, with no indexes on anything but the primary key(testxmlrid)
select count(testxmlrid) from testxml
where Attributes.value('(/form/fields/field/@id)[1]','integer')=1
This query on the otherhand takes about .75 seconds to run.
I'm using untyped XML and my benchmarking is taking place on a SQL Server 2008 Express instance. There are about 15,000 rows in the dataset and each XML string is about 25 lines long.
Are these results I'm getting correct? If so, why does everyone use .exist
? Am I doing something wrong and .exist
could be faster?