XQuery Rewrite Optimization in IBM DB2 pureXML

Fatma Özcan, Normen Seemann, Ling Wang

Abstract

IBM’s DB2 pureXML optimizes XQuery by employing a sophisticated rewrite engine that transforms complex, navigational queries into efficient, index-aware execution plans. By consolidating XPath steps into "pattern trees" and pushing predicates deep into the data access layer, the system achieves high throughput for semi-structured data. This paper details the integration of XQuery into the Query Graph Model (QGM) and the specific rewrite rules—such as XPath merging and join pull-up—that enable robust performance without requiring a fixed schema.

Introduction: The Challenge of XML Navigation

XML data is inherently hierarchical and semi-structured, presenting a significant challenge for traditional relational database optimizers designed for flat tables. While XQuery and SQL/XML are industry standards, executing them efficiently is difficult due to the "navigation" problem. In XQuery, traversing deep trees (e.g., /customer/order/item) can lead to performance degradation if each step is treated as a separate operation. Furthermore, the frequent lack of a rigid schema prevents optimizers from relying on static typing to predict data shapes.

Architectural Methods

The DB2 pureXML engine addresses these issues by integrating XQuery into the Query Graph Model (QGM), the internal representation used for SQL. This unified approach allows for the simultaneous optimization of hybrid SQL and XML queries.

Key Components

  • Unified Representation: Mapping both languages to QGM facilitates cross-language optimization.
  • New Quantifiers: The engine uses FOR to unnest XML sequences into rows and LET to aggregate rows back into sequences.
  • The ExpBox: This novel operator represents XML navigation as a "pattern tree." Instead of step-by-step execution, the ExpBox evaluates multiple paths and branches in a single pass, significantly reducing overhead.

Rule-Based Rewrite Engine

The core of the optimization lies in a set of transformations that simplify the query graph:

  • XPath Merging: Consolidating separate navigation steps into a single pattern tree.
  • Predicate Pushdown: Moving filters from "where" clauses directly into XPath navigation to enable XML value index usage.
  • Join Pull-up: Decorrelating queries by extracting join conditions from XPath expressions. This allows the optimizer to choose efficient join methods like hash joins rather than being restricted to nested loops.
Comparison of equivalent XQuery formulations for join operations.

As shown in the figure above, Query I and Query II are semantically identical but use different syntax (an XPath predicate versus a where clause). The rewrite engine must normalize these into a common form to ensure the cost-based optimizer can select the most efficient execution plan regardless of how the user authored the query.

Key Insights and Optimization Strategies

  • Holistic Navigation: By "co-mingling" XPath expressions into a single ExpBox, the system minimizes the data movement between operators.
  • Schema-Agnostic Type Inference: Without mandatory schemas, the engine uses type inference from function signatures and literals to drive optimization decisions.
  • Handling "EmptyOnEmpty": XQuery's requirement that a LET clause return an empty sequence if no data matches often blocks index usage. The authors developed a rewrite to "reset" this flag when a subsequent filter would discard empty results anyway, unlocking performance.
  • Input Independence: Merging XPaths requires determining if expressions are "input independent" to preserve node identity and document order rules.

Conclusion

The rewrite framework in DB2 pureXML enables the system to utilize XML value indexes that would otherwise be unreachable, reduces operation counts through graph simplification, and improves join flexibility. By decoupling the logical query structure from the physical execution plan, DB2 pureXML provides a scalable solution for managing complex semi-structured data.

Summary updated

BibTeX
@article{ozcan2008xquery,
  author = {Fatma Özcan and Normen Seemann and Ling Wang},
  title = {{XQuery Rewrite Optimization in IBM DB2 pureXML}},
  journal = {IEEE Data Eng. Bull.},
  year = {2008},
}
Figure