Vous êtes sur la page 1sur 22

XML and DB2

Tiina Pihlasviita
tiina.pihlasviita@fi.ibm.com
Putting DB2’s Power to Support XML

'%SURYLGHVVWDELOLW\VFDODELOLW\DQGVHFXULW\
<RXUPLVVLRQFULWLFDOEXVLQHVVGDWDLVFXUUHQWO\VWRUHG
LQ'%
'%
V;0/VXSSRUWDGGVLWVSRZHUWRHQDEOH\RXU
EXVLQHVVGDWDIRU;0/
:LWK'%
V;0/VXSSRUW\RXFDQFUHDWHDSSOLFDWLRQV
WR
Store XML documents for fast search
compose or decompose XML documents from or into relational tables
Query XML data based on XPath expressions
<RXFDQEXLOG%%DQG%&DSSOLFDWLRQVRQWRSRI'%
XVLQJ;0/([WHQGHU
XML Extender
Architecture
XML Extender Overview

Application File System


Program

XML
DAD Files
(Document
Access
Definition)

XML
DOC
DB2 XML
Extender DB2
XML Extender Architecture
&/,(17 6(59(5

DB2 CLIENT DB2 SERVER

XML EXTENDER
Admin GUI SERVER

Stored UDFs
Admin
procedures UDTs
Command

Customer Internal XML


client Utilities Parser
application
DB2: Two Access and Storage Methods
6WRUH8SGDWH

6HD
U F H
K5HWULHY

$SSOLFDWLRQ
;0/
'RFXPHQWV Document insertion, Document composition
update, & decomposition
deletion, search & retrieval

'7'
5HIHUHQFH
DTDs
Document Type
'%
Definition
7DEOH
;0/ ;0/
;0/ DADs
&ROXPQ &ROOHFWLRQ
8VDJH Document
Access
7DEOH
Definition

XMLCLOB

XML Side Tables Traditional


XML Column Tables
DAD: Document Access Definition
'$'!

GWGLG!F?G[[?VDPSOHV?GWG?JHWVWDUWGWGGWGLG!

YDOLGDWLRQ!<(6YDOLGDWLRQ!
;0/GRFXPHQWLWVHOI ;FROXPQ!

'HILQHWKHPDSSLQJEHWZHHQ;0/ WDEOHQDPH RUGHUBVLGHBWDE!

GRFXPHQWDQGUHODWLRQDOWDEOHV FROXPQQDPH RUGHUBNH\

W\SH LQWHJHU

)RU;0/&ROXPQLWODUJHO\GHILQHV SDWK 2UGHU#NH\


KRZGRFXPHQWVDUHLQGH[HGE\ PXOWLBRFFXUUHQFH 12!

FROXPQQDPH FXVWRPHU
GHILQLQJZKLFKHOHPHQWVDUH W\SH YDUFKDU  

H[WUDFWHGLQWRVLGHWDEOHV SDWK 2UGHU&XVWRPHU1DPH

PXOWLBRFFXUUHQFH 12!
)RU;0/&ROOHFWLRQVLWPDSVWKH WDEOH!
VWUXFWXUHRIWKH;0/GRFXPHQWWR WDEOHQDPH SDUWBVLGHBWDE!
'%WDEOHVDQGFROXPQV FROXPQQDPH SULFH

W\SH GHFLPDO  


:L]DUGDYDLODEOHWRDVVLVW'$' SDWK 2UGHU3DUW([WHQGHG3ULFH

FUHDWLRQ PXOWLBRFFXUUHQFH <(6!

WDEOH!

;FROXPQ!

'$'!
XML Column
;0/&ROXPQ "[POYHUVLRQ HQFRGLQJ 87)
VWDQGDORQ!
XML documents stored intact as DB2 '2&7<3(SHUVRQQHO5HF6<67(0SUPOGWG!
7KLVLVDFRPPHQW!
column data SHUVRQQHO5HF!
SHUVRQVDODU\ EDQG '!
with optional validation against DTDs QDPH!
IDPLO\!:DOODFHIDPLO\!
JLYHQ!%REJLYHQ!
Supplied User Defined Types QDPH!
XMLVarchar, XMLCLOB, XMLFile HPDLO!EZDOODFH#PHJDFRUSFRPHPDLO!
GHSW! GGHSW!
SHUVRQ!
Supplied User Defined Functions: SHUVRQQHO5HF!
To store or retrieve entire XML documents
into/from DB2
To extract or update XML elements or ;0/&ROXPQ

attribute values using XPath notation "[POYHUVLRQ HQFRGLQJ 87)


VWDQGDORQ!
'2&7<3(SHUVRQQHO5HF6<67(0SUPOGWG!
Document Access Definition: To define 7KLVLVDFRPPHQW!
SHUVRQQHO5HF!
special indexes {side tables} SHUVRQVDODU\ EDQG '!
for speedy structured search of XML QDPH!
IDPLO\!:DOODFHIDPLO\!
document content JLYHQ!%REJLYHQ!
QDPH!
for use in conjunction with regular SQL HPDLO!EZDOODFH#PHJDFRUSFRPHPDLO!
data GHSW! GGHSW!
SHUVRQ!
SHUVRQQHO5HF!
Can also use text extender text search
facilities
XML Columns - Side Tables
,QFUHDVHVSHUIRUPDQFHRIVHDUFKHV

&UHDWHV'%WDEOHVWRVWRUHLQGH[HVDQGIUHTXHQWO\
VHDUFKHGGDWD

7KHWDEOHVDUHV\QFKURQL]HGZLWKWKH;0/GRFXPHQW
ZLWK'%WULJJHUV

5HTXLUHVD'RFXPHQW$FFHVV'HILQLWLRQ '$' ILOHWR


GHILQHWKHPDSSLQJEHWZHHQWKH;0/GRFXPHQWDQGWKH
GDWDEDVHWDEOH

&DQQRWHQDEOHD;0/&ROXPQZLWKRXWDVLGHWDEOH
Using Side Tables for Fast Searches in XML
Documents
;0/&ROXPQ
RUGHUNH\

!

FXVWRPHU!7KRPSVRQFXVWRPHU!

SDUWNH\

!SDUW!
DAD
SDUWNH\

!SDUW! (Document
RUGHU! Access
Definition)

6DOHVBWDE
VLGHWDEOHV
Order
... (XMLCLOB)
... RUGHUBVLGHBWDE SDUWBVLGHBWDE
order_key customer part_key ....

99 Thompson 82 ....

... ... 83 ....

,QGH[ ,QGH[ ,QGH[


XML Collection
"[POYHUVLRQ HQFRGLQJ 87)
VWDQGDORQ!
;0/&ROOHFWLRQ '2&7<3(SHUVRQQHO5HF6<67(0SUPOGWG!
7KLVLVDFRPPHQW!
SHUVRQQHO5HF!
XML documents decomposed SHUVRQVDODU\ EDQG '!
QDPH!
XML elements and attributes IDPLO\!:DOODFHIDPLO\!
JLYHQ!%REJLYHQ!
stored as SQL data types QDPH!
HPDLO!EZDOODFH#PHJDFRUSFRPHPDLO!
XML documents composed or GHSW! GGHSW!
SHUVRQ!
reconstructed SHUVRQQHO5HF!

'$'
from regular SQL content held in
traditional tables
with optional validation against
DTDs
Document Access Definition: To
define mappings between relational
and XML data Salary
Person

Dept
XML Collection - Two Mapping Schemes
'$'!

64/PDSSLQJ FRPSRVLWLRQRQO\ GWGLG!F?G[[?VDPSOHV?GWG?JHWVWDUWGWGGWGLG!

YDOLGDWLRQ!<(6YDOLGDWLRQ!

;FROOOHFWLRQ!
SQL syntax
64/BVWPW!

specify the SQL select statement 6(/(&7

64/BVWPW!
specify the mapping between column and 
XML data in attribute_node and text_node ;FROOHFWLRQ!

'$'!
certain restrictions apply
5'%BQRGHPDSSLQJ FRPS  '$'!

GHFRPS


;FROOOHFWLRQ!


XML syntax HOHPHQWBQRGHQDPH 2UGHU!

specify tables and relationship among tables 5'%BQRGH!

WDEOHQDPH RUGHUBWDE!
in the RDB_node of the root element_node
WDEOHQDPH SDUWBWDE!

specify RDB_node with table name, column FRQGLWLRQ!

name and optional condition for RUGHUBWDERUGHUBNH\ 

attribute_node and text_node SDUWBWDESDUWBNH\

FRQGLWLRQ!

5'%BQRGH!
Use Text Extender on Structural Text Search
;0/FROXPQRUGHFRPSRVHGFROXPQLQVXEWDEOHVFDQEH
HQDEOHGZLWK7H[W([WHQGHU
perform structural and full text searches
8VH7H[W([WHQGHUVHFWLRQVXSSRUWRIVWUXFWXUDOWH[W
VHDUFKLQTXHU\
allows matching within a specific document context
([DPSOH
6(/(&7RUGHU)520VDOHVBWDEOH
:+(5(&217$,16 RUGHU+DQGOH

02'(/RUGHU6(&7,21 2UGHU&XVWRPHU
-RKQ'RH
 
1RGHSHQGHQF\RQ7H[W([WHQGHULIVHDUFKLQJRQ64/
GDWDW\SHVRI;0/HOHPHQWDWWULEXWHYDOXHVLVVXIILFLHQW
XML Columns vs XML Collections
5HDVRQVIRUFKRRVLQJ;0/&ROXPQ
XML documents already exist
Wish to store intact XML documents
Know which elements or attributes will be frequently searched
XML documents are frequently read but infrequently updated
Wish to keep XML documents external to DB2 on a file system

5HDVRQVIRU&KRRVLQJ;0/&ROOHFWLRQ
You need XML documents to be generated from your DB2 tables
You do not want to store intact XML documents, but only un-tagged
data
You know what column data in database to be used to generate XML
documents
You need to update small parts of XML documents often
Performance of update is critical
Dynamic Mapping

$ELOLW\WRWDNH'$'WRJHQHUDWHRUVKUHG;0/GRFXPHQWV
ZKHUH'$'FDQEHFUHDWHGE\DSSOLFDWLRQVRQWKHIO\
&KDQJHTXHU\FULWHULDYLDRYHUULGLQJTXHU\FRQGLWLRQIRUGRFXPHQW
JHQHUDWLRQ
64/B29(55,'(
replace the SQL query
change conditions in the WHERE clause
designed for DBMS experts
;0/B29(55,'(
Use XPath syntax to define element or attribute,
Specify the constraints on XML elements or attributes on the
documents to be generated
An example:
"/department/@id=’E01’ AND /department/name=’John Duo’ "
Other Features
Other Features

'7'5HSRVLWRU\
Store your DTDs in DB2,
One DTD can be referenced by many XML documents and more
than one XML column and XML collection.
Use DTDID to validate input XML documents at the insertion time

9DOLGDWLQJ,QSXWRU*HQHUDWHG;0/'RFXPHQWV
Validation can be specified in your DAD,
Supported in both XML Column and Collection features

*8,EDVHG$GPLQLVWUDWLRQ7RRO
Help to enable your database, tables. column, collection for XML
Help to create DAD
Document Type Definition - DTD

'7'VSHFLILHVWKHVWUXFWXUHRIDQ;0/GRFXPHQW
XML parsers can then understand and interpret the contents
contains a list of allowed tags with their types and attributes
can be stored in a separate file, or within the XML document itself
,WGHILQHVKRZHOHPHQWVUHODWHWRRQHDQRWKHUZLWKLQWKH
GRFXPHQWVWUHHVWUXFWXUH
'7'
VDUHXVHGWRGHWHUPLQHWKHYDOLGLW\RIDQ;0/
GRFXPHQW
'7'
VDUHXVHGWRSHUIRUPVWUXFWXUHGVHDUFKHVRQWKH
;0/GDWD
'7'
VFDQEHVKDUHGDFURVVRUJDQLVDWLRQV
Enterprise Integration
Challenge
Integrate islands of information to improve business effectiveness.
home grown, legacy applications
packaged apps
apps acquired through acquisitions
Solution
Leverage XML as the "lingua franca" to integrate and exchange information across the
enterprise.
Build enterprise models around XML to be used by new applications.
Provide portals with a service-oriented architecture.
Value
Extract competitive value from existing information.
Increase profitability through operational efficiencies.
Shorten business cycle (decision making process)
Technical Requirements
Integration of structured and unstructured data (including appl. data, e.g., SAP)
Application and process integration (messaging, workflow)
XML repository (XQuery, style sheet, XSchema, ...)
Mining of text data (categorization, search, ...)
DB2 Integrator Extends DM
DB2 UDB is optimized for high performance transaction and warehousing
support of structured information
supports replication, ETML, analysis and web services for structured information
provides XML based interfaces (e.g. SOAP, XQuery, SQLX) to support information
interchange
Content Manager is optimized for management of unstructured content
supports text search, workflow, versioning for unstructured information
provides XML based interfaces (e.g. SOAP, XQuery) for information interchange
DB2 Integrator is optimized to integrate structured, unstructured and XML
formatted information
supports federation, analysis, ETML, crawling & workflow/messaging integration and
web services across structured & unstructured & XML information
provides scalable, high-performance (native) XML storage for information integration
Going Forward
:KDWLVFRPLQJRXWLQ
%URDGHUFDSDELOLWLHVLQKDQGOLQJLQWHJUDWLQJVWUXFWXUHGDQGXQVWUXFWXUHGGDWD

DQG;0/

$FFHVVWRLQGXVWU\VSHFLILFGDWDVRXUFHV

([SDQGHGRXWUHDFKWR,69V6,V

6WUDWHJLFGLUHFWLRQ
;0/GDWDVWRUHIRUKLJKYROXPHDSSOLFDWLRQV
More information
'%8'%;0/([WHQGHU:HEVLWH
KWWSZZZVRIWZDUHLEPFRPGDWDGEH[WHQGHUV[POH[WLQGH[KWP O
KWWSZZZVRIWZDUHLEPFRPGDWDGEH[WHQGHUV[POH[WOLEUDU\KWPO

5HGERRNV ZZZUHGERRNVLEPFRP 
,QWHJUDWLQJ;0/ZLWK'%;0/([WHQGHUDQG'%7H[W([WHQGHU

6*

7RROV
O
KWWS[PODSDFKHRUJLQGH[KWP

KWWSZZZDOSKDZRUNVLEPFRPWHFK !;0/

,%0'DWD0DQDJHPHQW
KWWSZZZILLEPFRPVRIWZDUHGDWDLQGH[KWP O
;SHUDQWR
KWWS[SHUDQWRGIZLEPFRPGHPR