Storage structure for XML data

The storage structure for XML data is similar to the storage structure for LOB data.

As with LOB data, the base table that contains an XML column exists in a different table space from the table that contains the XML data.

The storage structure for the XML data depends on the type of table space that contains the base table, as described in the following table.

Table 1. Organization of base table spaces and corresponding XML table spaces
Base table space organization XML table space organization Remarks
Partition-by-growth1 Partition-by-growth An XML document can span more than one partition. The base table space and the XML table space grow independently.
partition-by-range 1 partition-by-range If a base table row moves to a new partition, the XML document also moves to a new partition.
Partitioned (non-UTS) partition-by-range If a base table row moves to a new partition, the XML document also moves to a new partition.

This table space type is deprecated.

Segmented (non-UTS) Partition-by-growth This table space type is deprecated.
Simple Partition-by-growth This table space type is deprecated.
Note:
  1. This table space organization supports XML versions.

The following figure demonstrates the relationship between segmented table spaces for base tables with XML columns and the corresponding XML table spaces and tables. The relationships are similar for simple base table spaces and partition-by-growth base table spaces. This figure represents XML columns that do not support XML versions.

Figure 1. XML storage structure for a base table in a segmented table space
Begin figure description. This figure shows the relationship between a segmented base table space and the associated XML table spaces. End figure description.

The following figure demonstrates the relationship between partitioned table spaces for base tables with XML columns and the corresponding XML table spaces and tables. The relationships are similar for partition-by-range base table spaces. This figure represents XML columns that do not support XML versions.

Figure 2. XML storage structure for a base table in a partitioned table space
Begin figure description. This figure shows the relationship between a partitioned base table space and the associated XML table spaces. End figure description.
When you create a table with XML columns or ALTER a table to add XML columns, the Db2 database server implicitly creates the following objects:
  • A table space and table for each XML column. The data for an XML column is stored in the corresponding table.

    Db2 creates the XML table space and table in the same database as the base table that contains the XML column. The XML table space is in the Unicode UTF-8 encoding scheme.

    If the base table contains XML columns that support XML versions, each XML table contains two more columns than an XML table for an XML column that does not support XML versions. Those columns are named START_TS and END_TS, and they have the BINARY(8) data type if the page format is basic 6-byte format and BINARY(10) data type if the page format is extended 10-byte format. START_TS contains the RBA or LRSN of the logical creation of an XML record. END_TS contains the RBA or LRSN of the logical deletion of an XML record. START_TS and END_TS identify the rows in the XML table that make up a version of an XML document.

  • An document ID column in the base table, named DB2_GENERATED_DOCID_FOR_XML, with data type BIGINT.

    DB2_GENERATED_DOCID_FOR_XML holds a unique document identifier for the XML columns in a row. One DB2_GENERATED_DOCID_FOR_XML column is used for all XML columns.

    The DB2_GENERATED_DOCID_FOR_XML column has the GENERATED ALWAYS attribute. Therefore, a value in this column cannot be NULL.

    If the base table space supports XML versions, the length of the XML indicator column is eight bytes longer than the XML indicator column in a base table space that does not support XML versions.

  • An index on the DB2_GENERATED_DOCID_FOR_XML column.

    This index is known as a document ID index.

  • An index on each XML table that Db2 uses to maintain document order, and map logical node IDs to physical record IDs.

    This index is known as a node ID index. The node ID index is an extended, non-partitioning index.

    If the base table space supports XML versions, the index key for the node ID index contains two more columns than the index key for a node ID index for a base table space that does not support XML versions. Those columns are named START_TS and END_TS, and they have the BINARY(8) data type.

You can perform limited SQL operations,on the implicitly created objects, such as altering the following attributes of an XML table space:

  • SEGSIZE
  • BUFFERPOOL
  • STOGROUP
  • PCTFREE
  • GBPCACHE

You can also the any except for the following attributes of the document ID index or node ID index:

  • CLUSTER
  • PADDED
  • Number of columns (ADD COLUMN is not allowed)

For a complete list of operations that you can perform on these objects, see ALTER TABLESPACE, ALTER TABLE, and ALTER INDEX.