Introduction
In Massively Parallel Processing (MPP) databases like Amazon Redshift, data is distributed across multiple compute nodes to enable parallel execution. However, the performance of these systems is heavily dependent on how data is partitioned. When joining two tables, the system achieves peak efficiency if matching rows reside on the same physical node—a state known as collocation.
If data is not collocated, the database must "reshuffle" or broadcast rows across the network during query execution. This network transfer often becomes the primary bottleneck for large-scale data warehouses. Choosing the optimal "distribution key"—the column used to hash data across nodes—is a complex combinatorial challenge, as a single table may be joined with many others on different columns.
The Distribution-Key Recommendation (DKR) Problem
The core challenge lies in identifying a distribution scheme that minimizes network traffic across a diverse workload. As illustrated in the figure below, an "Even" distribution (b) leads to data being scattered across nodes, necessitating expensive network transfers for joins. In contrast, a "Dist-Key" distribution (c) collocates related data (e.g., by state), significantly reducing the need for data movement.
The researchers formalize this as the Distribution-Key Recommendation (DKR) problem. They prove that finding the absolute optimal set of keys for a complex schema is NP-complete, meaning no perfect, fast algorithm exists for every case.
The BaW Framework
To solve the DKR problem efficiently, the authors introduced BaW (Best of All Worlds), a framework that treats database workloads as a graph problem.
1. Join Multi-Graph (JMG)
The workload is represented as a graph where vertices are tables and edges represent joins. Since tables can be joined on multiple columns, a "multi-graph" is used. The authors realized that choosing distribution keys is essentially a variation of the "Maximum Happy Edge Coloring" problem in graph theory. Edges are weighted by the volume of data moved (bytes processed) rather than simple query frequency, ensuring that the most expensive operations are prioritized. This approach is schema-independent, working equally well for Star, Snowflake, or complex "Big Data" schemas.
2. Optimization Algorithms
BaW employs a hybrid strategy to navigate the NP-complete search space:
- Integer Linear Programming (ILP): An exact mathematical solver used for smaller, simpler join graphs to find the theoretical optimum.
- Match-N-Grow (MNG): A fast heuristic that mimics graph matching techniques to find high-value collocations quickly.
- Meta-Algorithm: BaW runs the ILP with a strict time limit. If the optimal solution isn't found in time, it falls back to the best result from its suite of heuristics.
Experimental Results
The BaW framework was evaluated using real-world customer workloads, the industry-standard TPC-DS benchmark (3TB scale), and large-scale synthetic graphs.
- Massive Network Savings: On real-world datasets, the recommended keys reduced network communication costs by up to 32x.
- Query Speedups: In TPC-DS benchmarks, queries saw execution time improvements of up to 18x, as shown in the scatter plot in Figure 1(d). The BaW approach consistently outperformed standard even distribution strategies.
- Production Readiness: The algorithm is efficient enough to run in serverless environments like AWS Lambda, finding optimal keys for complex schemas in seconds or minutes.
Conclusion
The BaW framework provides a robust, graph-based approach to optimizing data distribution in Amazon Redshift. By focusing on data volume and leveraging a combination of exact solvers and powerful heuristics, it effectively eliminates network bottlenecks. Future work may extend this model to optimize for aggregations (GROUP BY) and integrate "Replicate All" strategies for small dimension tables to further enhance performance.
Summary updated