问题
I have a query that looks like the following:
SELECT
p.pProfileXml.value(''(Profile/ssn)[1]'', ''int'') ssn,
p.pProfileXml.value(''(Profile/date-birth)[1]'', ''date'') [date-birth],
p.pProfileXml.value(''(Profile/bad-field)[1]'', ''varchar(max)'') [bad-field],
p.pProfileXml.value(''(Profile/cb-bal)[1]'', ''float'') [e1_f1],
p.pProfileXml.value(''(Profile/date-hire-orig)[1]'', ''date'') [e1_f2],
p.pProfileXml.value(''(Profile/date-birth)[1]'', ''date'') [e2_f1]
FROM Profile p WHERE p.pgKey = 52
It takes about 20 seconds to run. There are ~300K rows in Profile table, of which ~43K are associated with pgKey = 52.
I was hoping to get this query much more performant. After adding Xml primary (and secondary) index(es), the execution time is now 30-40 seconds?!
Can anyone think/explain a reason why reading results from this table is now slower with XML Indexes on?
UPDATE
Some performance numbers:
-- Nonclustered pKey, no Xml Indexes - 10-11 secs
-- Clustered pKey, no Xml Indexes - 10 secs
-- Clustered pKey, Primary Xml Index - 37-41 secs
-- Clustered pKey, Primary Xml Index, secondary PROPERTY Index - 37-41 secs
Also, there seems to be an issue with my XML primary (secondary PROPERTY index). When I hover over index in execution plan, the number of rows read is always WAY bigger than actual rows. That seems wrong?
来源:https://stackoverflow.com/questions/62455933/sql-xml-query-slower-with-xml-indexes