MAPREDUCE服务 MRS-Flink SQL逻辑开发建议:多表left join时建议lookup join在所有双流join后

时间:2024-09-06 10:03:29

多表left join时建议lookup join在所有双流join后

多表left join时建议lookup join在所有双流join后,否则下游有left join LATERAL TABLE时会发生乱序。

图3 多表left join

虽然左表已经定义主键,但是经过lookup join后下游left join时无法推断左流主键,导致左流所有历史数据都存储在状态,右流数据到达后会从最新的状态开始依次回撤左流状态中的每一条数据,经过LATERAL TABLE每一条source数据又与lateral table自关联,数据乱序。

查看打印结果可以看到连续多条“-D”消息,并且最后一条数据错误,因此建议lookup join放在双流join后执行。

图4 连续多条“-D”消息
  • 优化前SQL:
    select... 
    from t1
    left join t2 FOR SYSTEM_TIME AS OF t1.proctime AS t21 on t21.id = t1.id
    left join t3 on t3.id = t1.id
    left join LATERAL TABLE(udtf()) AS  t4(res1,res2.res3,res4) on true
  • 优化后SQL:
    select... 
    from t1
    left join t3 on t3.id = t1.id
    left join t2 FOR SYSTEM_TIME AS OF t1.proctime AS t21 on t21.id = t1.id
    left join LATERAL TABLE(udtf()) AS  t4(res1,res2.res3,res4) on true
support.huaweicloud.com/devg-rule-mrs/mrs_07_450170.html