Skip to main content
Skew Join V2 is an advanced optimization feature in the database that addresses data skew issues in JOIN operations by broadcasting skew values. This feature significantly improves query performance when dealing with heavily skewed data distributions.

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:
  1. Identifying skew values: Manually specifying values that cause data skew
  2. Broadcasting skew values: Broadcasting these specific values to all nodes to ensure even data distribution
  3. Hybrid execution: Using a combination of shuffle and broadcast joins for optimal performance
Skew Join V2 creates a hybrid execution plan that combines:
  1. Shuffle Join: For non-skew data, uses the standard shuffle-based join
  2. 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.
After enabling Skew Join V2, you can then update your queries based on the syntax with explicitly specified skew values. Note Currently, Skew Join V2 does not support automatic plan rewrite based on statistics. Only hint-based manual SQL rewrite is supported.

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:
Parameters: [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.
Note Do not omit the brackets in the skew hint.

Examples

Basic Usage

  1. Create test tables.
  2. Insert sample data with skew.
  3. 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 skew hint 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:
Check the following fields in the plan:
  • SplitCastDataSink: Data splitting.
  • BROADCAST and SHUFFLE: Distribution type.
  • UNION: Union results of both Join types.