DB2 10 for Z/OS Purexml: Better and Faster
Total Page:16
File Type:pdf, Size:1020Kb
Information Management DB2 10 for z/OS pureXML: Better and Faster Guogen (Gene) Zhang, IBM May 2012 © 2010 IBM Corporation Information Management Agenda XML positioning and DB2 10 XML feature overview DB2 10 XML feature in detail –Enforcing XML schema conformance automatically –XML Date and Time support –Sub-document Update –Binary XML format for performance –SQL PL Stored Procs and UDFs –Simulating a queue –XQuery and if-then-else with regular expressions –CHECK DATA for XML Summary 2 © 2010 IBM Corporation Information Management DB2 XML Positioning Event/ Search Engine , Flexible/ Stream/ Complex (MapReduce) XML Schema IMS, IDMS Breaking relational limit Fixed Relational DB2 For application developers, new flexible data model Predefined Ad hoc and powerful language Queries to deal with new requirements. Rule of thumb: – Higher productivity No need to query – use LOB/VARCHAR/VARBINARY; – Shorter time to market Extensive queries over regular data -- use relational; Some queries on complex or flexible data – use XML For DBAs, use the familiar tools managing XML objects. – Manageability for XML data z platform: unparalleled reliability, availability, scalability, serviceability, and security. 3 © 2010 IBM Corporation Information Management Common XML Usage Scenarios Managing XML documents Object persistence Sparse attributes Front-end – bridge to back-end when full normalization is overkill Flexible structures – many scenarios Flexible parameter passing Web services Rapid prototyping Event logging End-user customizable applications/generators 4 © 2010 IBM Corporation Information Management Key XML Features in DB2 10 XML schema association with XML columns (a.k.a. XML column type modifier) and automatic schema validation for insert/update XML schema validation using z/OS XML System Services, 100% zIIP/zAAP redirectable (retrofit to V9) Native XML Date and Time support and XML index support Basic XML sub-document update XML support in SQL PL STP/UDF Performance enhancements, including binary XML between client and server. CHECK DATAT for XML, LOAD/UNLOAD Multi-versioning for concurrency control 5 © 2010 IBM Corporation Information Management Agenda XML positioning and DB2 10 XML feature overview DB2 10 XML feature in detail –Enforcing XML schema conformance automatically –XML Date and Time support –Sub-document Update –Binary XML format for performance –SQL PL Stored Procs and UDFs –Simulating a queue –XQuery and if-then-else with regular expressions –CHECK DATA for XML Summary 6 © 2010 IBM Corporation Information Management A Few Words about Multi-versioning format DB2 10 NFM, base table in UTS, XML will be in multi- versioning (MV) format MV format is required to support many new features for XML: –XMLMODIFY –Currently Committed –SELECT FROM OLD TABLE for XML –No XML locking for readers –Temporal data (“AS OF”) No automatic conversion from non-MV format to MV format (unfortunately) 7 © 2010 IBM Corporation Information Management Enforcing schema conformance automatically XML schemas as XML column type modifier, DB2 enforces the conformance. Example CREATE TABLE POTABLE ( ID INT, ORDER XML( XMLSCHEMA ID SYSXSR.PO1, URI 'uri' LOCATION 'location’), INVOICE XML); ALTER TABLE POTABLE ALTER INVOICE SET DATA TYPE XML( XMLSCHEMA URI ‘http://www.example.com/po’ ELEMENT “invoice”) Two ways to identify an XML schema (existing) – Schema name, or XSDs – target namespace + optional schema location XML Column XSDs 8 © 2010 IBM Corporation Information Management Automatic Validation Insert XSDs INSERT INTO purchase_orders XML VALUES (:id, :hv, NULL); XML Column Update XSDs UPDATE purchase_orders SET invoice =:hv; Load performing validation If the source is already validated according to the same XML schema in the type modifier, it won’t be revalidated again. Schemas evolve, multiple versions coexist – At insert/update time, choose one of them based on information from instance doc (target namespace, schema location). – If no schema location, with multiple schema matches, the latest will be chosen. 9 © 2010 IBM Corporation Information Management Alter XML type modifier Always use ALTER TABLE T1 ALTER X2 SET DATA TYPE XML(…): whole set of schemas – DB2 figures out the delta Change from Type To Type Modifier XML Table Space Impact Modifier No modifier PO Check pending PO1 PO1, PO2 No PO1 PO2 Check pending PO1, PO2 PO1 Check pending PO1 No modifier No 10 © 2010 IBM Corporation Information Management Schema Validation inside Engine Invoke z/OS XML System Services and make it 100% zIIP/zAAP redirectable UDF No need to specify schema in validation function. – Latest registered one will be chosen if there are multiple matches (better use schema location). Old syntax still works Examples INSERT INTO T1 VALUES (:hv) INSERT INTO T1 VALUES (DSN_XMLVALIDATE(:hv) ) You don’t need to call DSN_XMLVALIDATE if the column has schema modifier. You could specify preferred schema in the function. PK90032 and PK90040 retrofit SYSIBM.DSN_XMLVALIDATE to DB2 9. 11 © 2010 IBM Corporation Information Management Schema determination (1 of 4) XML Target Namespace Schema Location Registration schema Timestamp name PO1 http://www.example.com/PO1 http://www.example.com/PO1. 2009-01-01 xsd 10:00:00.0000 PO2 http://www.example.com/PO2 http://www.example.com/PO2. 2010-01-01 xsd 10:00:00.0000 PO3 NO NAMESPACE http://www.example.com/PO3. 2010-01-30 xsd 10:00:00.0000 PO4 http://www.example.com/PO2 http://www.example.com/PO4. 2010-02-23 xsd 08:00:00.000 Example 1: INSERT INTO purchase_orders VALUES(1, '<po:purchaseOrder xmlns:po="http://www.example.com/PO1"> ... </po:purchaseOrder> ); 12 © 2010 IBM Corporation Information Management Schema determination (2 of 4) XML Target Namespace Schema Location Registration schema Timestamp name PO1 http://www.example.com/PO1 http://www.example.com/PO1. 2009-01-01 xsd 10:00:00.0000 PO2 http://www.example.com/PO2 http://www.example.com/PO2. 2010-01-01 xsd 10:00:00.0000 PO3 NO NAMESPACE http://www.example.com/PO3. 2010-01-30 xsd 10:00:00.0000 PO4 http://www.example.com/PO2 http://www.example.com/PO4. 2010-02-23 xsd 08:00:00.000 Example 2: INSERT INTO purchase_orders VALUES(2, '<po:purchaseOrder xmlns:po="http://www.example.com/PO2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/PO2 http://www.example.com/PO2.xsd" > ... </po:purchaseOrder>'); 13 © 2010 IBM Corporation Information Management Schema determination (3 of 4) XML Target Namespace Schema Location Registration schema Timestamp name PO1 http://www.example.com/PO1 http://www.example.com/PO1. 2009-01-01 xsd 10:00:00.0000 PO2 http://www.example.com/PO2 http://www.example.com/PO2. 2010-01-01 xsd 10:00:00.0000 PO3 NO NAMESPACE http://www.example.com/PO3. 2010-01-30 xsd 10:00:00.0000 PO4 http://www.example.com/PO2 http://www.example.com/PO4. 2010-02-23 xsd 08:00:00.000 Example 3: INSERT INTO purchase_orders VALUES(2, '<po:purchaseOrder xmlns:po="http://www.example.com/PO2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/PO2 http://www.example.com/PO4.xsd"> ... </po:purchaseOrder>'); 14 © 2010 IBM Corporation Information Management Schema determination (4 of 4) XML Target Namespace Schema Location Registration schema Timestamp name PO1 http://www.example.com/PO1 http://www.example.com/PO1. 2009-01-01 xsd 10:00:00.0000 PO2 http://www.example.com/PO2 http://www.example.com/PO2. 2010-01-01 xsd 10:00:00.0000 PO3 NO NAMESPACE http://www.example.com/PO3. 2010-01-30 xsd 10:00:00.0000 PO4 http://www.example.com/PO4 http://www.example.com/PO4. 2010-02-23 xsd 08:00:00.000 Example 4: INSERT INTO purchase_orders VALUES(3, '<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi: noNamespace SchemaLocation ="http://www.example.com/PO3.xsd "> ... </purchaseOrder>'); 15 © 2010 IBM Corporation Information Management XML Schema Evolution Considerations Compatible changes: e.g. additional optional elements and attributes –Use new schema or schema versions (latest will be picked) Incompatible changes: mandatory new elements or attributes, different data types, different schema target namespace –DB2 can accommodate multiple schema versions or schemas –DSN_XMLVALIDATE can find the right schema versions given target namespace and schema location in instance documents –Application has to deal with document differences • Cardinality • Data types • Schemas –Conversions of old data to new data 16 © 2010 IBM Corporation Information Management XML Date and Time Support Date and time are not supported in XPath in V9 – Workaround: XMLTABLE and SQL date and time Add support xs:date, xs:time, and xs:dateTime and indexes for DATE and TIMESTAMP – Implicit timezone will be UTC if a date or time does not have a timezone – You get back the original or use fn:adjust-…-to-timezone() for a local timezone Supported types – xs:dateTime – xs:time – xs:date – xs:duration – xs:yearMonthDuration – xs:dayTimeDuration And a bunch of functions and operators: with time zone support, surpass SQL. 17 © 2010 IBM Corporation Information Management Examples XMLQUERY(‘/purchaseorder/items/item[shipdate > xs:date(“2007-01-31”)]’ PASSING X1) CREATE INDEX XIX1 ON T1(X1) GENERATE KEYS USING XMLPATTERN ‘/purchaseorder/items/item/shipdate’ as SQL DATE XMLQUERY(‘/purchaseorder [ordertime > xs:dateTime(“2007-01- 31T10:20:30-08:00”)]’ PASSING X1) – Note: xs:dateTime(“2007-01-31T10:20:30-8:00”) does not work CREATE INDEX XIX1 ON T1(X1) GENERATE KEYS USING XMLPATTERN ‘/purchaseorder/ordertime’ as