Deep Set Operators for XQuery

Bo Luo, Dongwon Lee, Wang-Chien Lee, Peng LiuXIME-P 2005

Introduction

Standard XQuery set operators—union, intersect, and except—treat XML nodes as flat, atomic entities. By operating strictly on node-IDs, they ignore the inherent tree-like structure of XML data. This paper introduces "deep" set operators that respect ancestor-descendant relationships, enabling more intuitive and structurally aware merging, filtering, and access control for XML documents.

The Structural Gap in XQuery

XML is fundamentally hierarchical; a node is essentially a "set of sets" containing all its descendants. Because standard operators ignore this hierarchy, they often yield counterintuitive results. For example, intersecting a parent node (//person) with its own child node (//person/name) in standard XQuery returns NULL because their node-IDs do not match.

In real-world applications, such as enforcing fine-grained XML access controls, developers need operators that understand when one node structurally subsumes another. A common requirement is granting access to a whole document except specific sensitive fields, such as credit card data.

A complete person node and its structural representation, illustrating the components targeted by deep operators.

Deep Set Operators

The authors formally define three new operators and implement them as engine-agnostic XQuery User-Defined Functions (UDFs):

  • deep-union: Returns a sequence containing nodes from either operand but eliminates redundant descendants. It retains only the "greatest common node" (the highest ancestor).
  • deep-intersect: Identifies structural overlaps. If one operand is an ancestor of the other, it returns the descendant (the overlapping portion), rather than NULL like a standard intersect would.
  • deep-except: This operator removes overlapping descendant or ancestor parts. If operand A is an ancestor of operand B, the operator dynamically constructs a new XML node that contains A's data minus B's subtree.
Visual logic of deep union (top) and deep intersection (bottom) operators.

Implementation and Performance

The deep operators were evaluated using the XMark schema on the Galax 0.5.0 engine. While the operators successfully provide structural awareness, they introduce performance overhead. Standard operators compare flat lists of IDs, whereas deep operators require traversing subtrees. deep-except is the most computationally expensive due to its recursive nature and the requirement to synthesize new XML nodes on the fly.

Preliminary tests on a 570KB document showed evaluation times under 0.5 milliseconds. However, as UDFs, these implementations rely on $O(n^2)$ comparisons, which may struggle with larger datasets.

Conclusion and Future Work

Deep set operators align XQuery with the natural, nested semantics of XML. While current UDF-based implementations are portable, they are limited by the performance constraints of query-level execution. Future work focuses on implementing these operators directly within XML database engines at the C/C++ level to leverage optimized $O(n \log n)$ algorithms.

Summary updated

BibTeX
@inproceedings{luo2005deep,
  author = {Bo Luo and Dongwon Lee and Wang-Chien Lee and Peng Liu},
  title = {{Deep Set Operators for XQuery}},
  booktitle = {XIME-P},
  year = {2005},
}
Figure