Native XML Support in DB2 Universal Database: Matthias Nicola, Bert Van Der Linden
Native XML Support in DB2 Universal Database: Matthias Nicola, Bert Van Der Linden
<dept>
<employee id=901>
<name>John Doe</name>
<phone>408 555 1212</phone>
<office>344</office>
</employee>
</dept>
NodeID
Identify matching nodes and regions within the documents
XML Value Indexes: atomic vs. non-atomic
Atomic Node:
if it is an attribute, or
if it is a text node, or
if it is an element that has no child elements
and exactly one text node child
Indexes typically defined for atomic nodes
Possible to define index on non-atomic
nodes, e.g. index on ‘/dept/employee’
XML Value Indexes: atomic vs. non-atomic
Example:
REGISTER XMLSCHEMA
http://my.dept.com FROM dept.xsd AS
departments.deptschema complete
Schema URI is http://my.dept.com
File with schema document is “dept.xsd”
Schema identifier in DB is “deptschema”
Belongs to relational DB schema
“departments”
XML Schema Support: Validation
Example (implcit)
DB2 tries to deduce schema from input
document
INSERT INTO dept(deptdoc) VALUES
xmlvalidate(?)
Try to find it in repository
XML Schema Support: First repository
design principle
order by $ml/shipno
return <MaintenanceLog>
{$ml/shipno,$ml}
</MaintenanceLog>
SQL Embedded in XQuery
for $m in db2-fn:sqlquery(‘select maintenance from ship where class = 1’)
let $ml := $m//log
order by $ml/shipno
return
<maintenanceLog>
{$ml}
</mantenanceLog>
This will return the documents for all class one ships.
Select Statement using XML
Column
Select shipno,class,maintenance
from ship
where class = 1
Updates
Use XMLParse command. You must specify
the entire XML column to update. If you
specify only 1 element to update, the rest of
the data will be lost.
Deletion
Same as standard SQL
Can also use xmlexists to use XML as
qualifier
Query Execution Plans
[2] Beyer, K., Cochrane, R. J., Josifovski, V., Kleewein, J., Lapis, G., Lohman, G., Lyle,
B., Özcan, F., Pirahesh, H., Seemann, N., Truong, T., Van der Linden, B., Vickery, B.,
and Zhang, C. 2005. System RX: one part relational, one part XML. In Proceedings of
the 2005 ACM SIGMOD international Conference on Management of Data
(Baltimore, Maryland, June 14 - 16, 2005). SIGMOD '05. ACM Press, New York, NY,
347-358.
[3] http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0603saracco2/