Breaking the Quadratic Barrier: Robust Cardinality Sketches for Adaptive Queries

Edith Cohen, Mihir Singhal, Uri Stemmer · DOI

Abstract

Cardinality sketches are fundamental tools in modern data systems, enabling the estimation of distinct elements in massive datasets with minimal memory overhead. However, these sketches are traditionally vulnerable to adaptive queries, where a user or adversary selects future queries based on the results of previous ones. In such settings, sketches of size $k$ typically fail after $O(k^2)$ queries—a phenomenon known as the quadratic barrier. This paper introduces a new class of estimators that break this barrier by reframing the problem through the lens of Adaptive Data Analysis (ADA). By shifting the focus from the total number of queries to the participation rate of individual elements, the proposed estimators can handle an exponential number of queries while maintaining high accuracy.

Introduction

In large-scale data processing, "sketches" like HyperLogLog or MinHash are indispensable for estimating the number of unique elements (cardinality) in a stream. These tools rely on internal randomness, typically via hashing, to provide compact representations of data. While these sketches are highly robust in non-adaptive settings—where queries are fixed in advance—they often collapse in adaptive environments.

In an adaptive setting, a feedback loop exists: the output of a query informs the construction of the next. Recent research has demonstrated that an adaptive adversary can exploit this feedback to "learn" the sketch's internal randomness, eventually crafting queries that force the estimator to produce significant errors. For a sketch of size $k$, this failure usually occurs after approximately $k^2$ queries. This "quadratic barrier" poses a significant risk to machine learning pipelines and automated data analysis tools where iterative querying is the norm.

Methodology: The ADA Perspective

To address this vulnerability, researchers from Google, UC Berkeley, and Tel Aviv University have moved beyond standard "robustness wrappers." Traditional methods often use Differential Privacy (DP) to hide a sketch's internal state, but these can be overly restrictive. Instead, this work reformulates sketching as a Statistical Query (SQ) problem within the framework of Adaptive Data Analysis (ADA).

The Bottom-$k$ Sketch

The authors focus on the bottom-$k$ sketch, a variant of MinHash. The core innovation lies in the realization that the quadratic barrier is not a hard limit on the total number of queries, but rather a limit on the information leaked about specific hash values. If individual keys are spread across many queries, the "leakage" per key remains low, preserving the sketch's integrity.

Proposed Estimators

The paper introduces two primary robust estimators:

  1. Basic Robust Estimator: This is a stateless estimator that employs a "noisy threshold" approach. It remains accurate as long as no single element in the ground set participates in more than $r \approx O(k^2)$ queries.
  2. Tracking Robust Estimator (TRobustEst): This stateful version tracks the "exposure" of each element. When an element reaches a specific participation limit ($r$), it is "deactivated" or ignored by the estimator. This allows the sketch to maintain accuracy for the remaining active elements, resulting in a "smooth degradation" of performance rather than a total collapse.

Experimental Evaluation

The estimators were evaluated using synthetic query sets designed to simulate various real-world data distributions, including uniform and skewed (Pareto) distributions. The experiments utilized a support size of $10^6$ keys and query sets of $5 \times 10^3$.

Key Results

The TRobustEst significantly outperformed theoretical baselines across all tested scenarios:

  • Uniform Distribution: The estimator achieved over a 100× gain in the number of supported queries compared to standard robust baselines.
  • Pareto Distribution ($\alpha=2$): In simulations of "heavy hitter" scenarios, the estimator achieved a 40× gain.
  • Highly Skewed Pareto ($\alpha=1.5$): Even in extreme skewness where tracking is most difficult, the system maintained a 12× gain.

These results confirm that by tracking and deactivating over-exposed keys—which are typically the primary drivers of sketch failure in skewed data—the remainder of the sketch remains highly reliable.

Discussion and Limitations

The theoretical implications of this work are profound: if per-key participation is limited to $O(k^2)$, the system can theoretically handle an exponential number of total queries without losing accuracy. This effectively "breaks" the quadratic barrier for most practical applications.

However, some limitations remain. The current proofs are specifically tailored to bottom-$k$ sketches. While the authors hypothesize that similar logic applies to HyperLogLog (HLL) and k-partition sketches, formal analysis for these structures is still required. Additionally, the authors note that $L_2$ norm estimation (such as AMS sketches) may be fundamentally harder to protect, as known quadratic attacks remain effective even when inputs are sparse.

Conclusion

By shifting the bottleneck of sketch robustness from the total query count to per-key participation, this research provides a scalable path for using cardinality sketches in adaptive environments. The introduction of the Tracking Robust Estimator offers a practical solution for maintaining data integrity in the face of feedback loops, ensuring that compact data summaries remain a viable tool for modern, iterative data science.

Summary updated

BibTeX
@inproceedings{cohen2025breaking,
  author = {Edith Cohen and Mihir Singhal and Uri Stemmer},
  title = {{Breaking the Quadratic Barrier: Robust Cardinality Sketches for Adaptive Queries}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=ratfqvU5GF},
}
Figure