Overview
Data skew occurs when certain values in join columns appear much more frequently than others, leading to uneven data distribution across nodes and causing performance bottlenecks. Skew Join V2 solves this problem by:- Identifying skew values: Manually specifying values that cause data skew
- Broadcasting skew values: Broadcasting these specific values to all nodes to ensure even data distribution
- Hybrid execution: Using a combination of shuffle and broadcast joins for optimal performance
- Shuffle Join: For non-skew data, uses the standard shuffle-based join
- Broadcast Join: For skew values, broadcasts the right table data to all nodes
Enabling Skew Join V2
By default, the Skew Join V2 optimization is disabled, and its predecessor, Skew Join V1, is enabled. If you find that the performance of Skew Join V1 is not satisfactory, you must disable Skew Join V1 before enabling Skew Join V2.Usage
Compared to the query rewrite method of Skew Join V1, Skew Join V2 offers a new syntax that allows you to explicitly specify the skew values with Broadcast. Syntax:[skew|table1.column(skew_value1, skew_value2, ...)]: The skew hint. It includes:
table1.column: The column from the left table that contains skew values.skew_value1, skew_value2, ...: A comma-separated list of values that cause data skew.
Examples
Basic Usage
-
Create test tables.
-
Insert sample data with skew.
-
Query data with Skew Join V2.
Multiple Skew Values
Skew Join V2 supports multiple skew values.Different Data Types
Skew Join V2 supports various data types for skew values.Complex Join Conditions
Skew Join V2 supports complex Join conditions.Different Join Types
Skew Join V2 supports various Join types.Best Practices
Step 1. Identify Skew Values
Before using Skew Join V2, identify the values that cause data skew:Step 2. Choose Appropriate Skew Values
Follow these rules to choose the appropriate skew values:- Include only the most frequent values that cause significant skew.
- Avoid including too many values as it may increase broadcast overhead.
- Consider the trade-off between skew optimization and broadcast cost.
Limitations
- Supported Join Types Currently, only INNER JOIN, LEFT JOIN, LEFT SEMI JOIN, and LEFT ANTI JOIN are supported.
- Data Types Currently, only basic data types (INT, BIGINT, STRING, DATE, DATETIME, and string types) are supported.
- Complex Expressions The support for complex expressions in Join conditions is limited.
- Skew Table Skew Join V2 can only handle scenarios where the large table in the JOIN operation is skewed, and the large table must be used as the left table.
- Join Reordering
Using the
skewhint will prevent the optimizer from reordering the Join. The Join will be executed in the order specified in the SQL, and the optimizer will not attempt to change the Join order or swap the left and right tables of the Join node containing the hint.
Troubleshooting
Debug Information
Execute EXPLAIN VERBOSE against the query to collect its execution plan:SplitCastDataSink: Data splitting.BROADCASTandSHUFFLE: Distribution type.UNION: Union results of both Join types.