Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to create a database solution that will enable me to optimise high CPU/IO/Duration queries to improve overall performance of the database.

Part of the optimisation requires persisting Query Plan XML to a table, then indexing it so that I can easily pull out the Warnings such as PlanAffectingConvert and fix these issues.

However, when I try to create a selective XML index on the table, like so:

CREATE SELECTIVE XML INDEX sxi_queryplan
ON dbo.Table(query_plan)
WITH XMLNAMESPACES(DEFAULT N'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
FOR
(
    pathQueryWarnings = '/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/QueryPlan/Warnings' AS XQuery 'node()'
)

...I get the following error:

An error occurred while executing batch. Error message is: Error processing execution plan results. The error message is:
There is an error in XML document (1, 1762).
Instance validation error: 'SelectiveXML' is not a valid value for IndexKindType.

The index is still created though, however whenever I then try to query the table, using the below, I get the same error as above.

WITH XMLNAMESPACES (DEFAULT N'http://schemas.microsoft.com/sqlserver/2004/07/showplan')
SELECT  query_plan FROM dbo.Table WHERE query_plan.exist('/ShowPlanXML/BatchSequence/Batch/Statements/StmtSimple/QueryPlan/Warnings') = 0

I've spent all morning trying to find the answer to this, but had no luck finding anythign about the Error Messages.

Without the index on the table, the above query works fine, suggesting the XML is not actually invalid. With it, I get the errors...

Any ideas?

share|improve this question
1  
The thing is that the referenced schema is not updated with the latest version of the schema. That does however not explain what you see because the schema is used only when you use it in typed XML. Are you using the query-plan xml somewhere with typed xml? Is the column defined as typed XML? –  Mikael Eriksson Jan 31 '14 at 14:09
    
If the XML column is typed and you somehow automagiccly capture the generated query-plans, then you would probably see this behaviour. Adding a selective index to a table will create a plan that contains the offending attribute so when that plan is captured and added to the table you get an exception but the index is still created. When you then query the table it will of course produce a query plan that uses the selective XML index and when that plan is added to the table you get the same error. –  Mikael Eriksson Jan 31 '14 at 14:21
    
The column is defined as XML, which would therefore explain the error. However I'm not automatically capturing the generated query-plans, it's a twice daily process. I guess without an updated schema from MS (which they seem in no hurry to do), I'll just have to live with not being able to index the XML data! –  Mark Sinkinson Jan 31 '14 at 14:37
    
Then I don't understand why this does not work for you. It should work fine with an untyped XML column. Are you executing the statements from SSMS or some other tool? –  Mikael Eriksson Jan 31 '14 at 15:34
    
Never mind...I had Actual Execution Plan on in SSMS...Sorry! –  Mark Sinkinson Jan 31 '14 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.