SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007
Agenda Background Testing Goals Indexing Results Query Results References
Background Why XML in a database? Semi-structured data Ease of Development Manageability
Background SQL Customer Lab What initiated the testing? Why Redmond?
Background XML Data type Indexes Primary Secondary Path Property Value XML Schemas
Background Element versus Attribute centric XML Element Attribute
Testing Goals xQuery vs T-SQL vs. hybrid queries Determine the feasibility of creating xQuery based views Evaluate the use of XML schemas Determine indexing strategy Greater understanding of the XML Datatype
Testing Methodology Loaded 1 million Policy versions created in element and attribute centric formats Suite of easy, medium and hard queries in T-SQL, xQuery, mixed and against views Space, performance and time statistics gathered for tests
Results: Attribute vs Element
Indexing Results Creation of Primary Index is not a parallel operation
Indexing Results Optimal indexes were 2.7 times the data size
Indexing Results Keep the number of attributes as low as possible
Who here worked with SQL 6.5?
Query Performance
xQuery performance varies greatly depending on quality of query Explicitly convert predicates to strings Use nodes method in the FROM clause Group fragment values together in the SELECT clause Use the exist() method on the XML data type whenever possible, instead of the value() method
Query Performance When comparing the same XML attribute to multiple values in a WHERE clause, list the name of the attribute on the outside of the predicate. For example, instead of this: WHERE PolicyXMLFragment.exist (' >= <= ] ') = 1 The XQuery should be written as this: WHERE PolicyXMLFragment.exist >= " " and. <= " "] ') = 1
Query Performance T-SQL outperforms xQuery Avoid views over xQuery Different query processors result in large amounts of data being moved between steps Where possible use T-SQL predicates to narrow down scope of xQuery
References XML Best Practices XML Support in SQL 2005 XML Data Type Performance Optimizations SQL Server 2005 XML