Viper IBM Db2 9: Under The Guidance of Rajeshwari HOD of Information Technology Dept
Viper IBM Db2 9: Under The Guidance of Rajeshwari HOD of Information Technology Dept
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
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 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).
Native XML data type (not Varchar, not CLOB, not object- relational) XML Capabilities in all DB2 components Applications combine XML & relational data
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
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
HASHED,
DB2 index manager enhanced to handle special XML types (e.g., +0, -0, +INF, -INF, NaN)
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
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
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
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)
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
is
specified explicitly, or can be deduced from the schemaLocation hints in the instance documents
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 )
</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>
This will return the documents for all class one ships.
This will produce the maintenance document for each ship that is class 1. We can also create views this way
SQL/XML Queries
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
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
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/