NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Weighted Random Sampling over Joins

Michael Shekelyan, Graham Cormode, Peter Triantafillou, Ali Mohammadi Shanghooshabad, Qingzhi MaarXiv 2022

Abstract

Joining large datasets often leads to a "join explosion," where the result set size dwarfs the input tables. While uniform sampling is common, many applications—such as privacy-preserving analytics and stratified sampling—require weighted random sampling (WRS). This paper introduces a novel, index-free streaming approach for WRS over multi-way joins. By utilizing a multipartite graph formulation and an online multinomial sampler, the proposed method avoids full materialization of join results, achieving significant memory savings and performance gains over traditional index-based methods.

Introduction

In modern data science, joining large datasets is a fundamental yet computationally expensive operation. A "join explosion" occurs when many-to-many relationships cause the resulting rows to exceed the size of input tables astronomically. While uniform random sampling can mitigate this, it is insufficient for scenarios requiring prioritization of specific records, such as weighting recent transactions or applying noise for differential privacy.

Existing solutions for weighted random sampling (WRS) typically rely on pre-computed indices. However, these indices are costly to build and maintain. This research presents a "practical sampler" that is ad-hoc, streaming, and memory-efficient, allowing for insights from massive joins without materializing the full result set.

Problem Statement

Relational joins can produce result sets much larger than the sum of their parts. While previous research has addressed uniform sampling, non-uniform (weighted) sampling is essential for:

  • Privacy-Preserving Analytics: Implementing differential privacy via non-uniform probabilities.
  • Stratified Sampling: Ensuring representation of rare but critical groups.
  • Accurate Aggregations: Biasing samples toward larger values to improve the precision of functions like SUM.

The challenge lies in creating a sampler that works on raw data (index-free) while minimizing data passes and memory usage.

Methodology: Multistage Multinomial Sampling

The authors propose a Multistage Multinomial Sampling framework consisting of three core innovations:

  1. Multipartite Graph Formulation: Joins are modeled as graphs where nodes represent rows and join attribute values. Dynamic programming is used to propagate weights from "leaf" tables back to a "main" table.
  2. Online Multinomial Sampler: A new algorithm draws a multinomial sample from a stream where weights are known only indirectly and the total population size is unknown. This allows picking "main" table rows in a single pass.
  3. Equi-Hash Joins: To handle join attributes with millions of unique values, a hashing technique relaxes the join condition to a "hash-match." This creates a manageable superset that is filtered to maintain exact sampling probabilities while reducing memory.
The proposed framework processes the largest table in one sequential scan and others in two, enabling efficient weighted sampling without full join materialization.

Evaluation and Results

The approach was evaluated using industry-standard and real-world datasets: TPC-H (SF 10 and 100), the Twitter Social Network, and the DBLP Citation Network.

Key Results

  • Memory Efficiency: The sampler required up to 10x less memory than index-based baselines. For a million-sample query on TPC-H (SF=100), memory usage dropped from ~95 GB to ~7 GB.
  • Performance: The streaming approach was up to 2x faster than the combined time of building indices and sampling.
  • Versatility: The method supports various join types, including outer joins, semi-joins, and anti-joins.
Taxonomy of join types supported by the streaming sampler, illustrating the flexibility of the multipartite graph approach.

Discussion and Insights

The research demonstrates that index-free methods can outperform index-based ones for one-off queries on new data. The ability to generate statistically valid weighted samples by scanning the largest table once and others twice proves that streaming is sufficient for large-scale join analytics. A key mathematical insight is the assumption of "factorized weights," where the weight of a join row is the product of weights from individual base rows, enabling the dynamic programming approach.

Limitations and Future Work

The primary challenge remains cyclic joins (e.g., triangle queries in social graphs). While a heuristic using rejection sampling is provided, cyclic joins can lead to high rejection rates. Future research will explore handling non-factorizable weights and extending the framework to more complex relational expressions beyond acyclic joins.

Summary updated

BibTeX
@misc{shekelyan2022weighted,
  author = {Michael Shekelyan and Graham Cormode and Peter Triantafillou and Ali Mohammadi Shanghooshabad and Qingzhi Ma},
  title = {{Weighted Random Sampling over Joins}},
  year = {2022},
  eprint = {2201.02670},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.02670},
}
Figure