pureXML lets DB2 for z/OS store well-formed documents as a first-class XML type — parsed, hierarchical, and queryable — instead of a CLOB of angle brackets. This page covers the XML column, the implicit XML table space and indexes Db2 builds for you, user XML indexes, performance, and how COPY/RECOVER treat XML the way they treat LOBs.
The XML data type defines columns that hold XML values. Most SQL statements accept the type: CREATE TABLE, ALTER TABLE ADD, CREATE INDEX over XML, triggers, INSERT, UPDATE, and DELETE. You can replace a whole document or, with XML functions covered on later pages, update pieces of it.
12345678910111213141516171819CREATE TABLE SALES.ORDER_XML ( ORDER_ID BIGINT NOT NULL, ORDER_DOC XML, PRIMARY KEY (ORDER_ID) ); INSERT INTO SALES.ORDER_XML (ORDER_ID, ORDER_DOC) VALUES ( 1001, XMLPARSE(DOCUMENT CAST( '' AS CLOB) ) ); SELECT ORDER_ID, XMLSERIALIZE(ORDER_DOC AS CLOB) AS ORDER_TEXT FROM SALES.ORDER_XML WHERE ORDER_ID = 1001; - WIDGET
XML values are not a string type. They are not compared to VARCHAR with ordinary =. Character data in the internal form uses UTF-8. To cross into text, use XMLSERIALIZE or fetch into a string/binary/XML host variable. To cross in from text, use XMLPARSE or insert from an XML application type.
Serialized XML stored in or retrieved from an XML column is limited to 2 GB. IBM describes internal size as not having the same architectural cap — plan the serialized path your programs actually use.
A table may have several XML columns plus ordinary relational columns. You can also extract nodes into relational tables with XMLTABLE and INSERT…SELECT if you need joins and foreign keys on values that started life inside the document.
IBM’s storage model for XML is similar to LOB storage: the base table that contains the XML column lives in a different table space from the table that contains the XML data. The difference is that you do not CREATE AUXILIARY TABLE for XML. When you create or ALTER ADD an XML column, Db2 implicitly creates the XML objects. Applications never name the XML table space on INSERT.
| Object | Role |
|---|---|
| Base table with XML column | Relational keys plus an XML column the application names |
| XML table space + XML table | One pair per XML column; UTF-8; same database as the base table |
| Document ID index | Unique index on the document ID; points at the base RID. NPSI if the base is partitioned |
| Node ID index | Extended NPI on the XML table: document order and logical node ID to physical RID |
| XML index (XMLPATTERN) | Optional user index on selected nodes for query performance |
If the base table space supports XML versions, each XML table has extra START_TS and END_TS columns (BINARY(8) or BINARY(10) depending on 6-byte vs 10-byte page format). They hold the RBA/LRSN of logical creation and deletion of an XML record so several versions of a document can coexist. The node ID index key gains the same columns.
If an edit procedure is defined on the base table, the XML table inherits it. Implicit XML table space attributes are copied from the base (and from the first logical partition) so DSSIZE, SEGSIZE, compression, and locking behavior stay in family:
| Attribute | Inherited from |
|---|---|
| COMPRESS, DSSIZE, SEGSIZE, MAXPARTITIONS, PAGENUM | Base table space (with version-specific notes) |
| FREEPAGE, PCTFREE, GBPCACHE, STORNAME, TRACKMOD, VCATNAME | First logical partition of the base table space |
| LOCKMAX, LOG, CLOSERULE | Base table space |
| Encoding | XML table space is Unicode UTF-8 regardless of base CCSID |
These indexes are not optional decorations. The document ID index is a unique index that maps document ID to the base table RID. If the base is partitioned, it is a non-partitioned secondary index (NPSI). The node ID index is an extended non-partitioning index on the XML table. Db2 uses it to keep document order and to map logical node IDs to physical record IDs.
Do not DROP them to “save space.” You would break XML access. RUNSTATS and COPY should include their index spaces along with the XML table space.
User-defined XML indexes are how you make “find orders where /order/status = 'OPEN'” cheap. You specify an XML pattern — a limited XPath — and Db2 generates keys from matching nodes.
1234CREATE INDEX SALES.ORDXML_STATUS ON SALES.ORDER_XML (ORDER_DOC) GENERATE KEY USING XMLPATTERN '/order/status' AS SQL VARCHAR(20);
Design notes:
| Lever | When it helps |
|---|---|
| XMLPATTERN indexes | Frequent predicates on the same elements or attributes |
| Do not SELECT the whole document | List screens; use XMLQUERY/XMLTABLE to project nodes, or relational summary columns |
| Buffer pools | XML table spaces may deserve their own pool if documents are large and sequential |
| Validation cost | XMLVALIDATE on every INSERT is correctness, not free — validate at the edge if documents are trusted |
| Inline thinking does not apply the same way | XML is not an INLINE LENGTH LOB; storage is always the XML table space model |
Fetching XMLSERIALIZE(doc AS CLOB) for every row in a 2-million-row table is the XML equivalent of SELECT * on a CLOB. Project ORDER_ID and a status column (relational or XMLQUERY) for lists. Open the document on the detail transaction.
Parsing on INSERT (XMLPARSE, implicit parse from a string, XMLVALIDATE) is CPU. If the same document is stored many times, validate once at the gateway. If documents vary wildly in size, watch XML table space DSSIZE and the number of partitions on the base: XML volume follows base partitions but can dwarf them.
Binary XML (XDB) client formats exist so JDBC/ODBC can avoid extra parse/serialize on the wire. That is an application driver setting, not a column attribute, but it belongs in a performance review next to XML indexes.
Utility support for XML is modeled on LOB support. XML data is not in the base table space. XML table spaces have their own index spaces. Implications:
Disaster-restart runbooks that list table spaces by name must be regenerated after the first XML column is added. Implicit names are easy to miss in a handwritten COPY list. LISTDEF with a pattern on the database, or a catalog query of SYSTABLESPACE for the XML spaces, is safer than memory.
Schema validation and the XML schema repository (XSR) are covered on the XML schema pages. Storage takeaway: validation does not change the fact that the document lives in the XML table space; it only changes whether INSERT is allowed.
An XML document is a set of labeled boxes inside boxes. The XML column is a special shelf for those boxes. Db2 does not cram the boxes onto the same notebook page as the order number; it builds a second warehouse (XML table space) and keeps two card catalogs: one that finds the notebook row from the document (document ID index) and one that finds each box inside the warehouse (node ID index). If you often ask “which orders are OPEN?”, you can add a sticky index on the status box (XMLPATTERN). Backup means photographing both the notebook and the warehouse on the same day, or the story and the boxes will not match.
1. What does Db2 create when you add an XML column?
2. How is XML stored compared with a CLOB of tags?
3. What is an XML index (the user-defined kind)?
4. Where does XML data for a partitioned base table live?
5. How should you COPY a table with XML columns?