Updated on 2026-06-27 GMT+08:00

Using Multi-Joins in Flink SQL

Scenarios

Flink SQL supports multi-joins, which effectively reduces intermediate states in multi-table join scenarios.

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 using multi-joins to combine multiple tables, the join keys for all tables must be identical.
  • This section applies only to MRS 3.6.0-LTS.1 and later.

How to Use

To enable the multi-join function, add the custom parameter table.optimizer.multi-join.enabled and set its value to true on the Flink job development page of the FlinkServer web UI. For details, see Creating a FlinkServer Job.

Example SQL statement:
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 datagen5 (id int, f5 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
  (
    'connector' = 'datagen',
    'rows-per-second' = '1'
  );
CREATE TABLE datagen6 (id int, f6 int, PRIMARY KEY (id) NOT ENFORCED)
WITH
  (
    'connector' = 'datagen',
    'rows-per-second' = '1'
  );
CREATE TABLE print (id int, f1 int, f2 int, f3 int, f5 int, f6 int)
WITH
  ('connector' = 'print');

insert into
  print
select
  datagen1.id,
  datagen1.f1,
  datagen2.f2,
  datagen3.f3,
  datagen5.f5,
  datagen6.f6
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 datagen6 on datagen1.id = datagen6.id
  and datagen6.id > 6
  and datagen1.id > 1;