snuyanzin commented on code in PR #22558:
URL: https://github.com/apache/flink/pull/22558#discussion_r1239021813
##########
flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/rules/logical/subquery/SubqueryCorrelateVariablesValidationTest.xml:
##########
@@ -99,4 +99,34 @@ LogicalProject(min_t3d=[$9], max_t2h=[$11])
]]>
</Resource>
</TestCase>
+ <TestCase name="testWithFilterJoinCorrelate">
+ <Resource name="sql">
+ <![CDATA[
+SELECT t1a
+FROM t1
+WHERE EXISTS (SELECT max(t2h) FROM t2
+ LEFT OUTER JOIN t1 ttt
+ ON t2.t2a=t1.t1a)
+ ]]>
+ </Resource>
+ <Resource name="ast">
+ <![CDATA[
+LogicalProject(t1a=[$0])
++- LogicalFilter(condition=[EXISTS({
+LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
+ LogicalProject(t2h=[$7])
+ LogicalJoin(condition=[=($0, $cor0.t1a)], joinType=[left])
+ LogicalTableScan(table=[[default_catalog, default_database, t2, source:
[TestTableSource(t2a, t2b, t2c, t2d, t2e, t2f, t2g, t2h, t2i)]]])
+ LogicalTableScan(table=[[default_catalog, default_database, t1, source:
[TestTableSource(t1a, t1b, t1c, t1d, t1e, t1f, t1g, t1h, t1i)]]])
+})], variablesSet=[[$cor0]])
+ +- LogicalTableScan(table=[[default_catalog, default_database, t1, source:
[TestTableSource(t1a, t1b, t1c, t1d, t1e, t1f, t1g, t1h, t1i)]]])
+]]>
+ </Resource>
+ <Resource name="optimized rel plan">
Review Comment:
The query is
```sql
SELECT t1a
FROM t1
WHERE EXISTS (SELECT max(t2h) FROM t2
LEFT OUTER JOIN t1 ttt
ON t2.t2a=t1.t1a)
```
inside `EXISTS` there is aggregate `MAX` which always returns a record. Even
for empty table it returns a row with `null` inside. In this case `exists` is
always `true`.
The optimization does similar analysts based on metadata of the query.
From this point of view it looks correct...
Or did I miss anything?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]