Cardinality Estimation on Hyper-relational Knowledge Graphs

Fei Teng, Haoyang Li, Shimin Di, Lei Chen · DOI

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.

The HRQE architecture, detailing the four-step process from input query graph to final cardinality estimation.

Core technical innovations include:

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Performance comparison of HRQE against baseline models, highlighting its superior accuracy (mean q-error) and competitive inference times.

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

BibTeX
@misc{teng2024cardinality,
  author = {Fei Teng and Haoyang Li and Shimin Di and Lei Chen},
  title = {{Cardinality Estimation on Hyper-relational Knowledge Graphs}},
  year = {2024},
  eprint = {2405.15231},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.15231},
}
Figure