Adding Domain Knowledge to Query-Driven Learned Databases

Peizhi Wu, Ryan Marcus, Zachary G. IvesarXiv 2023 · DOI

Abstract

Learned cardinality estimators—AI models that predict query results—often fail because they lack "common sense" about fundamental database operations. We present CORDON (Constraining Output Ranges with Domain Oriented kNowledge), a semi-supervised framework that integrates traditional database constraints directly into the machine learning training loop. By teaching models the underlying rules of data, CORDON produces estimators that are more accurate, robust to out-of-distribution queries, and require up to 50% less training data than state-of-the-art baselines.

Introduction

In modern database systems, cardinality estimation is critical for query optimization, as it determines the fastest execution plan. Recently, "query-driven" learned models (such as MSCN) have emerged, learning from historical query performance. However, these models often operate as "black boxes," lacking an understanding of the logical rules governing the data. For instance, a model might predict that a join returns more rows than exist in its constituent tables— a logical impossibility in Primary Key-Foreign Key (PK-FK) relationships. This lack of domain knowledge leads to high data requirements and poor performance on "out-of-distribution" (OOD) queries.

The CORDON Framework

CORDON addresses these limitations by injecting database "common sense" into neural networks through a semi-supervised approach. The framework focuses on three primary constraint classes:

  1. PK-FK Inequality: Ensuring a join does not return more rows than the fact table.
  2. PK-FK Equality: Identifying scenarios where a join should not alter the row count.
  3. Consistency: Ensuring that the sum of predictions for partitioned range queries (e.g., "age < 20" and "age ≥ 20") equals the prediction for the combined range.
The CORDON architecture integrates domain knowledge into the training process via logic rules and a specialized constraint interface.

As shown in the architecture above, CORDON implements these rules via Logic Loss Functions, which penalize the model for logical violations, and Data Augmentation, which generates provably correct training examples from schema rules. To maintain efficiency, a Random Choice strategy selects one applicable constraint per training step.

Addressing Logical Inconsistency

Standard learned models frequently violate basic database logic. Analysis of existing state-of-the-art models reveals significant distributions in "impossible" regions, such as predicting join results that exceed table sizes or failing basic additive consistency for range queries.

Violin plots illustrating how standard models violate (a) consistency and (b) PK-FK inequality constraints, with many predictions falling into "Too High" or "Definitely Incorrect" regions.

CORDON uses these constraints to "box in" predictions, acting as a shield against the wild, impossible guesses typically seen when models encounter unfamiliar data.

Experimental Evaluation

The researchers evaluated CORDON using the IMDb (JOB-light) dataset, the DSB (Data Services Benchmark), and a new DKS (Domain Knowledge-Sensitive) workload designed to highlight logical failures.

Key Results

  • Improved Accuracy: On the DSB dataset, CORDON improved the accuracy (q-error) of OOD queries by up to 95% compared to the baseline MSCN model.
  • Data Efficiency: The framework achieved standard accuracy levels while requiring 50% to 70% less labeled training data, demonstrating that domain knowledge can effectively substitute for expensive execution data.
  • Reduced Violations: Significant logical constraint violations were reduced by 50-60% across all tested datasets.
  • System Performance: When integrated into PostgreSQL, CORDON's improved estimates led to end-to-end query runtime improvements of 20% to 50% on specialized workloads.

Conclusion and Future Work

CORDON demonstrates that integrating domain-specific logic is a powerful "force multiplier" for learned database components. While the current framework focuses on cardinality estimation, future work may extend these principles to full cost estimation (predicting execution time) and explore more sophisticated sampling strategies for constraint generation. Despite some computational overhead in advanced features like pseudo-labeling, CORDON represents a significant step toward robust, logically-consistent AI for database management.

Summary updated

BibTeX
@misc{wu2023adding,
  author = {Peizhi Wu and Ryan Marcus and Zachary G. Ives},
  title = {{Adding Domain Knowledge to Query-Driven Learned Databases}},
  year = {2023},
  eprint = {2312.01025},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.01025},
}
Figure