Sie sind auf Seite 1von 34

Viper IBM Db2 9

Under The guidance of Rajeshwari HOD of Information Technology Dept

B.Sandeep Kumar 08W81A1237

What is DB2 9 (Viper)? Native XML in the forthcoming version of DB2 Native XML Storage XML Schema Support XML indexes Querying XML data in DB2 Summery

What is DB2 9 (Viper)?

IBM DB2 9 is the next-generation hybrid data server with optimized management of both XML and relational data. IBM extended DB2 to include: New storage techniques for efficient management of hierarchical structures inherent in XML documents. New indexing technology New query language support (for XQuery), a new graphical query builder (for XQuery), and new query optimization techniques

New support for validating XML data based on usersupplied schemas

New administrative capabilities, including extensions to key database utilities Integration with popular application programming interfaces (APIs)

Historical Background
The idea of a relational database first arose in 1970 when Dr. E.F. Codd formally stated a number of algebraic rules that could be applied to data manipulation. DB2 was the name given to the Database Management System in 1982, and it is the first database to use SQL. At first, DB2 was only available on IBM mainframes, but during the 1990's DB2 spread to many other platforms, LUW (Linux, Unix, Windows), mid-range computers i5/OS (formerly AS/400) and even on PDAs. The Universal Server shifted the technology to an object-related SQL DBMS that allows developers to define their own data types from more primitive data types. In 2006, IBM announced "Viper," the codename for DB2 9 on distributed platforms and DB2 9 on z/OS. DB2 9 offers the ability to store XML "natively," and it also allows storage compression to save on disk space. IBM refers to the ability to store XML as pure XML(tm).

Architecture Of IBM DB2 9

Integrating XML and Relational in DB2 9

DB2 Hybrid XML Engine - Overview

Integration of XML & Relational Capabilities in DB2

Native XML data type (not Varchar, not CLOB, not object- relational) XML Capabilities in all DB2 components Applications combine XML & relational data

Native XML Storage

XML Node Storage Layout

XML Storage: Regions Index

XML Indexes in DB2

Need index support to manage millions of XML documents Path-specific value indexes on XML columns to index frequently used elements and attributes XML-aware full-text indexing

XML Value Indexes


Table DEPT has two fields: id and dept_doc Field dept_doc is an XML document: <dept> <employee id=901> <name>John Doe</name> <phone>408 555 1212</phone> <office>344</office> </employee> </dept>

CREATE INDEX idx1 ON DEPT(deptdoc) GENERATE KEY USING XMLPATTERN /dept/employee/name AS SQL VARCHAR(35) Creates XML value index on employee name for all documents

XML Value Indexes: Data Types

Allowed data types for indexes:


VARCHAR(n) VARCHAR DOUBLE DATE TIMESTAMP

HASHED,

DB2 index manager enhanced to handle special XML types (e.g., +0, -0, +INF, -INF, NaN)

XML Value Indexes: unique indexes

Unique indexes enforced within a document, and across all documents Example of unique index on employee id: CREATE UNIQUE INDEX idx2 ON DEPT(deptdoc) GENERATE KEY USING XMLPATTERN /dept/employee/@id AS SQL DOUBLE

XML Value Indexes: internal

For each XML document, each unique path mapped to an integer PathID (like StringID for tags) Each index entry includes:
PathID to identify path of indexed node Value of the node cast to the index type RowID Identify rows containing the matching documents NodeID Identify matching nodes and regions within the documents

XML Schema Support

Optional XML Schema validation Insert, Update, Query Type annotation produced by validation persisted with document (query execution) Conforms to XML Query standard, XML Schema standard, XML standard

XML Schema Support

Register XML Schemas and DTDs in DB DB then stores type-annotated documents on disk, compiles execution plans with references to the XML Schemas Schemas stored in DB itself, for performance XML Schema Repository (XSR)

XML Schema Support: Registration

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

XMLVALIDATE function to validate documents in SQL statements Schema for validation

is

specified explicitly, or can be deduced from the schemaLocation hints in the instance documents

Referenced by Schema URI or by identifier

Querying XML Data in DB2

Options Supported XQuery/XPath as a stand-alone language SQL embedded in XQuery XQuery/XPath embedded in SQL/XML Plain SQL for full-document retrieval DB2 treats SQL and XQuery as primary query languages. Both will operate independently on their data models Can also be integrated

Sample Tables
create table ship ( shipNo capacity class purchDate maintenance )
varchar(5) primary key not null, decimal(7,2), int, Notice the date, xml datatype xml

create table captain ( captID varchar(5) primary key not null, lname varchar(20), fname varchar(20), DOB date, contact xml )

Sample XML Data Ship.maintenance


<mrecord> <log> <mntid>2353</mntid> <shipno>39</shipno> <vendorid>2345</vendorid> <captid>9875</captid> <maintdate>01/10/2007</maintdate> <service>Removed rust on hull </service> <resolution>complete</resolution> <cost>13450.96</cost> <nextservice>01/10/2008</nextservice>

</log> <log>
<mntid>1254</mntid> <shipno>39</shipno> <vendorid>1253</vendorid> <captid>9234</captid> <maintdate>09/20/2005</maintdate> <service>Replace rudder</service> <resolution>complete</resolution> <cost>34532.21</cost> <nextservice>NA</nextservice> </log> </mrecord>

Sample XML Data Captain.contactinfo


<contactinfo> <Address> <street>234 Rolling Lane</street> <city>Rockport</city> <state>MA</state> <zipcode>01210</zipcode> </Address> <phone> <work>9783412321</work> <home>9722342134</home> <cell>9782452343</cell> <satellite>2023051243</satellite> </phone> <email>love2fish@finmail.com</email> </contactinfo>

Standalone XQuery in DB2


for $s in db2-fn:xmlcolumn(ship.maintenance) let $ml:= $s//log Db2-fn:xmlcolumn returns sequence of all documents where $ml/cost = > 10000 in the XML column 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

This will produce the maintenance document for each ship that is class 1. We can also create views this way

SQL/XML Queries

Restricting results using XML element values


select

captid,lname,fname from captain where xmlexists($c/contactinfo/Address[state=MA] passing captain.contact as c

This will return the captid, lname and fname of all captains who live in Massachusetts

SQL/XML Queries

Projecting XML element values Two functions: XMLQuery and XMLTable XMLQuery retrieves value for 1 element XMLTable retrieves value for multiple elements XMLQuery example: select xmlquery($c/contactinfo/email passing contact as c) from captain where state = MA This will return email addresses for all captains in Massachusetts

Updating and Deleting XML Data

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


Separate parsers for SQL and XQuery statements Integrated query compiler for both languages QGMX is an internal query graph model Query execution plans contain special operators for navigation (XSCAN), XML index access (XISCAN) and joins over XML indexes (XANDOR) Source: [2]

Query Run-time Evaluation

3 major components added for processing queries over XML:


XML Navigation XML Index Runtime XQuery Function Library

Developing Java applications for XML data

References
[1] Nicola, M. and van der Linden, B. 2005. Native XML support in DB2 universal database. In Proceedings of the 31st international Conference on Very Large Data Bases (Trondheim, Norway, August 30 - September 02, 2005). Very Large Data Bases. VLDB Endowment, 1164-1174.
[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/

Das könnte Ihnen auch gefallen