Database Reference
In-Depth Information
Atomization of nodes occurs only when an XML instance is untyped. Let's see what happens with the typed XML
data, as shown in Listing 11-9 and Figure 11-5 .
Listing 11-9. Typed XML data and atomization of nodes
declare
@X xml (document ElementCentricSchema) =
'<Order>
<OrderId>42</OrderId>
<OrderTotal>49.96</OrderTotal>
<CustomerId>123</CustomerId>
<OrderNum>10025</OrderNum>
<OrderDate>2013-07-15T10:05:20</OrderDate>
<OrderLineItems>
<OrderLineItem>
<ArticleId>250</ArticleId>
<Quantity>3</Quantity>
<Price>9.99</Price>
</OrderLineItem>
<OrderLineItem>
<ArticleId>404</ArticleId>
<Quantity>1</Quantity>
<Price>19.99</Price>
</OrderLineItem>
</OrderLineItems>
</Order>'
select @X.value('(/Order/CustomerId)[1]','int')
Figure 11-5. Typed XML and atomization of nodes
As you see, there is no atomization of nodes overhead. SQL Server knows that CustomerId is an integer rather
than a section. This is another benefit of preserving XML type information with XML Schema collections.
Finally, let's check out what happen when we have a primary XML index defined, and we run the same method
against one of the rows from the ElementCentricTyped table, as shown in Listing 11-10. The execution plan is then
shown in Figure 11-6 .
Listing 11-10. Calling the XML data type method when XML index is present
select XmlData.value('(/Order/CustomerId)[1]','int')
from dbo.ElementCentricTyped
where ID = 1
 
Search WWH ::




Custom Search