XML Showplans
In Microsoft SQL Server 2005, Showplan execution plan output can be generated in XML format by various methods. Showplan output in XML format can be moved from one computer to another and thus rendered on any computer, even on computers where SQL Server is not installed. Showplan output in XML format can also be programmatically processed using XML technologies, such as XPath, XQuery, XSLT, SAX, DOM, and so on. XML Showplan processing is supported in SQL Server 2005, which contains a built-in query evaluation engine for XPath and XQuery.
You can generate XML Showplan output by using the following methods:
- Selecting Display Estimated Execution Plan or Include Actual Execution Plan from the query editor toolbar in SQL Server Management Studio
- Using the Transact-SQL Showplan SET statement options SHOWPLAN_XML and STATISTICS XML
- Selecting the SQL Server Profiler event classes Showplan XML, Showplan XML for Query Compile, and Showplan XML Statistics Profile for tracing
- Using the sys.dm_exec_query_plan dynamic management function
XML Showplans are returned in the nvarchar(max) data type for all of these methods, except when you use sys.dm_exec_query_plan. XML Showplans are returned in the xml data type when you use this dynamic management view.
The XML schema for Showplan is available at this Microsoft Web site.
It is also available in the directory where SQL Server 2005 is installed at the following location:
Microsoft SQL Server\90\Tools\Binn\schemas\sqlserver\2004\07\showplan\showplanxml.xsd
Note
If the query optimizer prematurely terminates query optimization, the StatementOptmEarlyAbortReason attribute is returned for the StmtSimple element in XML Showplan output. The possible values that can display for this attribute are TimeOut, GoodEnoughPlanFound, and MemoryLimitExceeded. If TimeOut or GoodEnoughPlanFound are returned for this attribute, no action is necessary. The Showplan returned contains correct results. If MemoryLimitExceeded is returned for the StatementOptmEarlyAbortReason attribute, the XML Showplan produced will still be correct, but it may not be optimal. Try one of the following methods to increase available memory: 1) Reduce the load on the server. 2) Increase memory available to SQL Server. For more information, see Managing Memory for Large Databases. 3) Check the max server memory option that is set with sp_configure, and increase the value if it is too low. For more information, see Server Memory Options.
About the Showplan XML Schema
Version designation of the Showplan XML Schema consists of two parts, such as m.n, where m is the major version number and n is the minor version number. For example, "Version 2.5." This version number appears in the Showplan XML Schema document root element. For example: version="0.5"
Backward Compatibility of Showplan XML Schemas
When the major version number increments, new XML Showplan output may not validate against the old schema. However, if the minor version number increments, there is no effect. For example, if you have generated XML Showplan output with schema version 0.5, that output validates against a Showplan XML schema version 0.6.
Encoding of XML Showplans
SQL Server 2005 sends the XML Showplan output to the client in Unicode format using two bytes for each character sent. The encoding rules are as follows:
- If (char >= 0x0020 && char <= 0xD7FF) or (char == 0x0009) or
(char == 0x000A) or (char == 0x000D) or (char >= 0xE000 && char <= 0xFFFD)
then send the char as 2 bytes, else send '?' - Tab, newline, and linefeed characters are encoded as follows:
- \t is encoded as '	'
- \n is encoded as '
'
- \r is encoded as '
'
Saving XML Showplan Output to a File
After Showplan output has been generated by using either the SHOWPLAN_XML or the STATISTICS XML Transact-SQL SET statements, you can save the output to a file with the extension .sqlplan. For example, MyXMLShowplan.sqlplan. These .sqlplan files can then be opened and viewed in SQL Server Management Studio. For more information, see How to: Save an Execution Plan in XML Format.
See Also
Reference
Displaying Graphical Execution Plans (SQL Server Management Studio)
Concepts
Displaying Execution Plans by Using the Showplan SET Options (Transact-SQL)
Displaying Execution Plans by Using SQL Server Profiler Event Classes
Showplan Security
Other Resources
Help and Information
Getting SQL Server 2005 Assistance
Change History
Release | History |
---|---|
5 December 2005 |
|