Optimal time sampling method speeds up queries on large acyclic joins

Optimal-Time Independent Subset Sampling over Acyclic Joins

DatabasesData Structures and Algorithms

Summary

When databases combine tables to answer questions, they sometimes create huge results even if only a small part is needed. The authors created a way to quickly pick a random sample of results without going through everything slowly. Their method uses clever math and data structures to speed up this process, especially for queries involving tables joined in certain simple patterns. Tests show it works faster than previous methods on real data.

What this means in practice

  • For database administrators: Efficiently sample join query results with large datasets for faster analytics and exploratory data tasks.
  • For statistical data analysts: Generate independent random subsets from complex database joins to enable scalable statistical modeling on weighted data.

Authors

Xuyang Liu, Zijian Zhang, Zhen Li

Abstract

Join results can greatly exceed their inputs even when applications need only a small random subset. We study sampling that includes each result independently with a prescribed probability given by the product of its input-tuple weights (PRODUCT). For fixed full acyclic joins with static weights, we achieve input-linear preprocessing and index space together with output-linear expected sampling work, eliminating logarithmic factors from previous bounds. A shared join-tree index supports weighted draws over the entire join and locates high-probability results. Direct Bernoulli trials handle high-probability results, allowing Poisson thinning to generate the remaining independent inclusion decisions with bounded overhead. Our exact sampler uses expected $O(N)$ preprocessing, $O(N)$ index space, and expected $O(1+mμ)$ time per call including output construction. Here $N$ is the input size, $m$ counts relation occurrences, and $μ$ is the expected sample size. The guarantees hold on a real random-access machine with unit-cost exact arithmetic and logarithms, continuous uniform randomness, and expected-time hashing. The time bounds are optimal, matching input reading and explicit output writing. Our floating-point prototype has lower sampling latency than the fastest applicable baseline in 17 of 18 PRODUCT settings on three queries over the STATS benchmark. Construction savings on large joins can offset indexed materialization's faster sampling over a limited number of calls. On a real-data path at $μ=100$, our sampler achieves a $20.5\times$ speedup over indexed materialization for construction plus 300 calls, measured after common data preparation and loading.