Convolution and Cross-Correlation of Count Sketches Enables Fast Cardinality Estimation of Multi-Join Queries

Mike Heddes, Igor Nunes, Tony Givargis, Alex Nicolau

Abstract

Cardinality estimation—predicting the size of join results—is a critical component of database query optimization. In streaming environments, researchers have long faced a trade-off between the slow but join-capable AMS sketches and the fast but join-incompatible Count sketches. This paper introduces a novel sketching framework that bridges this gap by replacing standard element-wise multiplication with circular convolution and cross-correlation. By leveraging the Fast Fourier Transform (FFT), the proposed method enables Count sketches to estimate multi-join cardinalities with $O(1)$ update times, achieving throughput up to six orders of magnitude higher than traditional methods without sacrificing theoretical accuracy.

Introduction: The Cardinality Estimation Dilemma

In modern data systems, query optimizers rely on cardinality estimation to select efficient execution plans. For multi-table joins in high-speed streams, the challenge is two-fold: maintaining accurate statistics and updating them in real-time.

Historically, two algorithms dominated the landscape:

  1. AMS Sketches: Capable of handling complex joins but computationally expensive. Every incoming tuple requires updating all $m$ counters in the sketch, leading to significant latency.
  2. Count Sketches: Highly efficient due to a "hashing trick" that updates only a few counters per item. However, their sparsity makes them incompatible with the standard Hadamard (element-wise) product used to combine sketches for join estimation.

Proposed Method: Convolutional Count Sketches

The core innovation of this work is the realization that the mathematical operation used to combine sketches—not the sketches themselves—was the primary limitation. The authors propose replacing element-wise multiplication with circular convolution during data ingestion and circular cross-correlation during query inference.

Comparison of update mechanisms: AMS vs. Count sketches.

As shown in the figure above, the Count sketch update is localized to a single bin $h(i)$, whereas the AMS sketch requires a global update. By treating the update as a circular convolution of single-item sketches, the information is "spread" across the sketch in a way that preserves join information even under sparse conditions.

System Architecture

The proposed system integrates these sketches into a unified query-processing engine.

High-level architecture of the stream query-processing engine.

The engine ingests multiple data streams ($R_0, R_1, \dots, R_{r-1}$), maintaining corresponding sketches in memory. When a query $Q$ arrives, the system uses the Fast Fourier Transform (FFT) to compute cross-correlations across the join graph in nearly linear time relative to the sketch size.

Experimental Evaluation

The researchers evaluated the method using the IMDB (Join Order Benchmark) and STATS (Stack Exchange) datasets, testing over 3,200 sub-queries to capture the skew and complexity of real-world data.

Key Results

  • Throughput: The system achieved over 6 million updates per second, maintaining constant performance even as sketch sizes reached $10^6$. In contrast, AMS throughput plummeted to a few hundred updates per second.
  • Accuracy: The method provided "error-free" estimates for 70% of sub-queries and maintained a q-error $< 2$ for 95% of cases, outperforming modern machine learning-based estimators like DeepDB.
  • Real-World Impact: Integration with PostgreSQL resulted in a 43% improvement in total query execution time compared to the native optimizer.

Conclusion and Future Work

By reconciling the speed of Count sketches with the join-processing capabilities of AMS sketches, this work provides a scalable solution for real-time cardinality estimation. While the variance of the estimator grows with the number of relations ($3^r$) and query inference involves a slight FFT overhead, the authors argue these are negligible trade-offs given the massive gains in data ingestion speed. Future research will focus on mitigating the exponential variance to support "mega-joins" involving dozens of tables.

Summary updated

BibTeX
@article{heddes2024convolution,
  author = {Mike Heddes and Igor Nunes and Tony Givargis and Alex Nicolau},
  title = {{Convolution and Cross-Correlation of Count Sketches Enables Fast Cardinality Estimation of Multi-Join Queries}},
  journal = {Proc. ACM Manag. Data},
  year = {2024},
  doi = {10.1145/3654932},
}
Figure