18
SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Embed Size (px)

DESCRIPTION

Background Why XML in a database?  Semi-structured data  Ease of Development  Manageability

Citation preview

Page 1: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

SQL Server 2005 XML Datatype

David Wilson

Ohio North SQL Server Special Interest GroupJuly 12, 2007

Page 2: 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

Page 3: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Background

Why XML in a database? Semi-structured data Ease of Development Manageability

Page 4: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Background

SQL Customer Lab What initiated the testing? Why Redmond?

Page 5: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Background

XML Data type Indexes Primary Secondary

Path Property Value

XML Schemas

Page 6: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Background Element versus Attribute centric XML

Element<Policy>

<Fields> <code>3</code> < policynumber>1234567</policynumber>

</Fields></ Policy >

Attribute< Policy >

<Fields code="3" policynumber=“1234567"></Fields> </ Policy >

Page 7: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

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

Page 8: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

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

Page 9: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Results: Attribute vs Element

Page 10: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Indexing Results Creation of

Primary Index is not a parallel operation

Page 11: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Indexing Results Optimal indexes were 2.7 times the data size

Page 12: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Indexing Results Keep the number of attributes as low as possible

Page 13: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Who here worked with SQL 6.5?

Page 14: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Query Performance

Page 15: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

Query Performance xQuery performance varies greatly depending on

quality of queryExplicitly convert predicates to stringsUse nodes method in the FROM clauseGroup fragment values together in the SELECT

clause Use the exist() method on the XML data type

whenever possible, instead of the value() method

Page 16: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

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('

/Fields[@pol_dt >= 20061201 and@pol_dt <= 20061231]

') = 1

The XQuery should be written as this:WHERE

PolicyXMLFragment.exist('

@pol_dt[. >= "20061201" and. <= "20061231"]

') = 1

Page 17: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

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

Page 18: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007

References XML Best Practices

http://msdn2.microsoft.com/en-us/library/ms187508.aspx XML Support in SQL 2005

http://msdn2.microsoft.com/en-us/library/ms345117.aspx XML Data Type Performance Optimizations

http://msdn2.microsoft.com/en-us/library/ms345118.aspx SQL Server 2005 XML

http://msdn2.microsoft.com/en-us/sql/aa336361.aspx