1. 问题
select * from source_table
where data.empUid in (select data.empUid from source_table2)
执行原理
2.执行计划
explain select * from source_table a where a.data.empUid in (select data.empUid from source_table2 )
== Optimized Execution Plan ==
Calc(select=[op, data, occur_time, proctime])
+- Join(joinType=[LeftSemiJoin], where=[($f4 = empUid)], select=[op, data, occur_time, proctime, $f4], leftInputSpec=[NoUniqueKey], rightInputSpec=[NoUniqueKey])
:- Exchange(distribution=[hash[$f4]])
: +- Calc(select=[op, data, occur_time, PROCTIME_MATERIALIZE(PROCTIME()) AS proctime, data.empUid AS $f4])
: +- TableSourceScan(table=[[default_catalog, default_database, source_table]], fields=[op, data, occur_time])(reuse_id=[1])
+- Exchange(distribution=[hash[empUid]])
+- Calc(select=[data.empUid AS empUid])
+- Reused(reference_id=[1])
转换成了 left semijoin
3. 统计数据
实时sql 有这个毛病, 即使看了执行计划,也不能具体知道它咋执行的, 可能还是基本功不够吧。set table.exec.state.ttl= 20 s;
source_table 和source_table2 分别从俩topic 取数, 每5秒一条。
- 当source_table2 没有数据时, 没有输出。 符合预期。
- 当source_table2 开始写入数据时, 立刻输出4条数据。
- 当source_table2 停止数据写入时,过20s 后, 没有数据输出。
所以:source_table 如果没有匹配上,会被缓存状态,受ttl影响。直达状态过期删除或者匹配成功输出。
source_table2 会被换缓存为状态,受ttl影响。