Efficient Massively Parallel Join Optimization for Large Queries

Riccardo Mancini, Srinivas Karthik, Bikash Chandra, Vasilis Mageirakos, Anastasia Ailamaki

TL;DR

This paper introduces MPDP, a massively parallel join optimization algorithm that leverages GPUs to find optimal query plans for large joins significantly faster than existing methods. By combining the high parallelizability of subset-based enumeration with the pruning efficiency of graph-based approaches, the authors achieve up to an 80x speedup over state-of-the-art parallel CPU algorithms, allowing databases to find optimal plans for 25+ relations in under two seconds.

What Problem Does This Paper Address?

In relational databases, "join order optimization" is the process of deciding the most efficient sequence to join multiple tables. Because the number of possible sequences grows exponentially with the number of tables, this is an NP-hard problem.

Modern data workloads often involve "long" queries with dozens or even hundreds of tables. Most current optimizers (like those in PostgreSQL or SparkSQL) hit a "wall" around 12–18 tables; beyond that, they switch from searching for the optimal plan to using "heuristics" (educated guesses). These heuristics are fast but often produce plans that are orders of magnitude slower to execute. The challenge is: how can we push the boundary of "optimal" planning further and improve the quality of heuristics for massive queries?

Methods

The authors propose a two-pronged approach:

  1. MPDP (Massively Parallel Dynamic Programming): This is the core algorithm designed for GPUs. It bridges the gap between two traditional approaches:
  2. Vertex-based (DPSub): Highly parallelizable but evaluates many "invalid" join pairs (sets of tables that aren't actually connected in the query).
  3. Edge-based (DPCCP): Very efficient at pruning invalid pairs but difficult to parallelize due to complex dependencies.
  4. The Innovation: MPDP identifies "blocks" (biconnected components) in the join graph. It uses vertex-based enumeration within blocks to maintain parallelism and edge-based enumeration between blocks to prune the search space.
  5. GPU-Specific Optimizations: To make MPDP fly on hardware like the NVIDIA GTX 1080, the authors implemented:
  6. Collaborative Context Collection: A technique to prevent "branch divergence," where GPU threads waste time waiting for each other during complex conditional checks.
  7. Kernel Fusion: Reducing slow global memory writes by performing pruning steps directly in shared memory.
  8. UnionDP: A new heuristic for queries with 100s to 1000s of tables. It partitions the massive join graph into "tractable" sub-problems, solves each optimally using MPDP, and then recursively combines the results.

Datasets

The authors evaluated their work using:

  • MusicBrainz: A real-world dataset of music metadata (56 tables).
  • JOB (Join Order Benchmark): A standard industry benchmark for testing query optimizer quality.
  • Synthetic Workloads: Star, Snowflake, and Clique join graphs designed to test the limits of the algorithm's pruning and scaling capabilities.
  • TPC-H: Used for illustrative examples.

Key Insights and Ideas

  • The "Invalid Pair" Gap: The authors found that for a 25-table star join, standard parallel algorithms evaluate 2,800 times more invalid join pairs than valid ones. MPDP slashes this overhead by using graph topology.
  • Hybrid Enumeration: The "aha moment" is that you don't have to choose between parallelism and pruning. By isolating biconnected components, you can restrict the expensive "blind" search to small sub-graphs while using the graph's structure to link them.
  • Hardware Matters: Join optimization is often seen as a CPU-bound task. This paper proves that with the right data structures (like bitmasks for table sets) and divergence-handling techniques, the massive SIMD (Single Instruction, Multiple Data) power of GPUs is a perfect fit for the combinatorial explosion of DP.

Key Results

  • Speedup: On a 23-relation query, MPDP (GPU) was 80x faster than the state-of-the-art parallel CPU algorithm (DPE) and 19x faster than previous GPU-based DP implementations.
  • Pushing the Limit: MPDP can find the optimal plan for 25 relations in the same time budget PostgreSQL takes for just 12.
  • Heuristic Quality: For massive queries (up to 1,000 tables), the UnionDP heuristic produced plans that were up to 7x cheaper (in terms of estimated execution cost) than existing state-of-the-art heuristics.
  • Efficiency: MPDP optimized a 1,000-relation query in under one minute.

Limitations and Future Work

  • Join Types: The current implementation focuses on inner equi-joins. The authors note that extending this to handle hypergraphs (required for non-inner joins like outer joins or anti-joins) is a subject for future work.
  • Cardinality Estimation: While MPDP finds the "optimal" plan according to the cost model, the plan is only as good as the database's underlying statistics. The authors acknowledge that improving cardinality estimation is a separate but related challenge.
  • Integration: The implementation requires code changes to the database optimizer module, which may be a hurdle for adoption in some legacy systems.

Summary updated

BibTeX
@inproceedings{mancini2022efficient,
  author = {Riccardo Mancini and Srinivas Karthik and Bikash Chandra and Vasilis Mageirakos and Anastasia Ailamaki},
  title = {{Efficient Massively Parallel Join Optimization for Large Queries}},
  booktitle = {SIGMOD},
  year = {2022},
  url = {https://openreview.net/forum?id=VBLIDXNLVUU},
}

Loading related content...

Figure