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

Post on 06-Jan-2018

227 views 0 download

description

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

Transcript of SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12,...

SQL Server 2005 XML Datatype

David Wilson

Ohio North SQL Server Special Interest GroupJuly 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<Policy>

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

</Fields></ Policy >

Attribute< Policy >

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

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

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

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

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

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