sql server 2005 xml datatype david wilson ohio north sql server special interest group july 12, 2007
DESCRIPTION
Background Why XML in a database? Semi-structured data Ease of Development ManageabilityTRANSCRIPT
![Page 1: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/1.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/2.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/3.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/4.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/5.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/6.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/7.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/8.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/9.jpg)
Results: Attribute vs Element
![Page 10: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/10.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/11.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/12.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/13.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/14.jpg)
Query Performance
![Page 15: SQL Server 2005 XML Datatype David Wilson Ohio North SQL Server Special Interest Group July 12, 2007](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/15.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/16.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/17.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022062503/5a4d1ade7f8b9ab0599762d6/html5/thumbnails/18.jpg)
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