Using Multi-Joins in FlinkSQL
Scenario
In FlinkSQL multi-table join scenarios, multiple join operations are executed one by one by default. Each join operation generates an independent intermediate state. When a large number of tables are joined, intermediate states accumulate significantly, consuming substantial storage resources and degrading job performance. FlinkSQL supports multi-join, which allows multiple join operations to be combined into a single multi-join operator in multi-table join scenarios, effectively reducing intermediate states.
Notes and Constraints
- Multi-joins do not support the Join-to-Live feature.
- Snapshots taken before and after a multi-join operation are incompatible.
- When multi-join is used to join multiple tables, the table join keys must be consistent.
Usage
You can use either of the following methods to set table.optimizer.multi-join.enabled to true to enable the multi-join function:
- Method 1: When configuring a Flink job, add this custom parameter to the flink_config parameter of the job.
- Method 2: Add this custom parameter to the Flink parameters of the endpoint.
SQL Example
CREATE TABLE datagen1 (id int, f1 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
(
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE datagen2 (id int, f2 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
(
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE datagen3 (id int, f3 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
(
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE datagen4 (id int, f4 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
(
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE datagen5 (id int, f5 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
(
'connector' = 'datagen',
'rows-per-second' = '1'
);
CREATE TABLE print (id int, f1 int, f2 int, f3 int, f4 int, f5 int)
WITH
('connector' = 'print');
insert into
print
select
datagen1.id,
datagen1.f1,
datagen2.f2,
datagen3.f3,
datagen4.f4,
datagen5.f5
from
datagen1
left join datagen2 on datagen1.id = datagen2.id
and datagen2.id > 2
join datagen3 on datagen1.id = datagen3.id
and datagen3.id > 3
right join datagen5 on datagen1.id = datagen5.id
and datagen5.id > 5
full outer join datagen4 on datagen1.id = datagen4.id
and datagen4.id > 4
and datagen1.id > 1; Multi Join Operator Supporting Empty Result Pruning
Scenario
During the running of the Multi Join operator, empty result pruning is supported. When the state corresponding to a table is empty, the traversal of this state is skipped. This reduces invalid recursive scans in the Multi Join operator and improves query performance and resource utilization.
Usage
Set parameter table.optimizer.multi-join.empty-result-pruning.enabled to true to enable the empty result pruning function.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot