Abstract: Cardinality estimation (CE) is a fundamental task in query optimization, predicting the number of results a query will return to select the most efficient execution plan. While CE is well-established for traditional triple-based knowledge graphs (KGs), modern hyper-relational knowledge graphs (HKGs) introduce "qualifiers"—additional contextual data such as time or location—that significantly complicate estimation. This paper presents HRQE (Hyper-relational Query Encoder), a novel Graph Neural Network (GNN) framework designed specifically for HKGs. HRQE explicitly models qualifiers through a specialized message-passing scheme and handles incomplete queries using a Conditional Variational Autoencoder (CVAE). We also introduce three new, complex benchmarks to address the lack of diverse datasets in this domain. Experimental results show that HRQE outperforms state-of-the-art methods by orders of magnitude in accuracy while maintaining millisecond-level inference efficiency.
Introduction
In database systems, the query optimizer relies on Cardinality Estimation (CE) to choose between different execution strategies. Modern data is increasingly represented in hyper-relational formats, where facts are not just simple (Subject, Predicate, Object) triples but are enriched with qualifiers. For example, the fact that Barack Obama was President of the USA is qualified by his term dates. Existing CE methods fail on HKGs because they either ignore qualifiers or fail to find valid subgraphs during sampling due to the increased constraint density.
Methods
The proposed HRQE framework addresses these gaps through four integrated steps: initialization, qualifier completion, message passing, and estimation.
Core technical innovations include:
- Qualifier-aware GNN: HRQE uses a composition function to integrate qualifier information directly into relation embeddings during message passing, treating qualifiers as fundamental structural constraints.
- CVAE-based Qualifier Completion: To manage queries that do not specify all possible qualifiers, a Conditional Variational Autoencoder (CVAE) infers missing data, allowing the model to generalize to broader query intents.
- Adaptive Multi-layer Combination: The framework adaptively weights outputs from different GNN layers to handle various query topologies (e.g., chains, stars, petals, flowers) and prevent over-smoothing.
- Data Augmentation: Auxiliary queries are generated to teach the model the logic of relative cardinality—specifically, that adding constraints must result in a cardinality less than or equal to the original.
Datasets
The authors identified that existing benchmarks like WD50K-QE were insufficient for evaluating complex hyper-relational queries. Consequently, they developed three new benchmarks: WD50K, JF17K, and Wikipeople. These datasets feature complex topologies (such as "Petals" and "Flowers") and a wide range of result sizes, providing a more rigorous testing ground for CE models.
Results
HRQE was evaluated against several state-of-the-art baselines. The primary performance metric was the q-error, representing the ratio between predicted and actual cardinalities.
Key results include:
- Accuracy: HRQE achieved significantly lower q-errors than all competitors. On the WD50K benchmark, HRQE's q-error was 297, compared to over 8,000 for the next best baseline.
- Efficiency: Inference times remained in the 5-6ms range, demonstrating the model's suitability for real-time database optimization.
- Generalization: The model proved robust in inductive settings, maintaining performance on previously unseen entities and query patterns.
Conclusion
HRQE represents a significant advancement in cardinality estimation for hyper-relational data. By integrating qualifiers into the core GNN architecture and utilizing generative models for completion, it achieves unprecedented accuracy. Future work will focus on extending the framework to support complex logical operators like negation and disjunction.
Summary updated