You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "swuferhong (via GitHub)" <gi...@apache.org> on 2023/03/01 07:37:13 UTC
[GitHub] [flink] swuferhong opened a new pull request, #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
swuferhong opened a new pull request, #22049:
URL: https://github.com/apache/flink/pull/22049
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
This pr is aims to fix left join with IS_NULL filter be wrongly pushed down and get wrong join results. The example case is:
`SELECT * FROM MyTable1 LEFT JOIN MyTable2 ON a1 = a2 WHERE a2 IS NULL AND a1 < 10`. For this query, the planner will get a wrong plan:
`LogicalProject(a1=[$0], b1=[$1], c1=[$2], b2=[$3], c2=[$4], a2=[$5])
+- LogicalFilter(condition=[IS NULL($5)])
+- LogicalJoin(condition=[=($0, $5)], joinType=[left])
:- LogicalValues(tuples=[[]])
+- LogicalTableScan(table=[[default_catalog, default_database, MyTable2]]) `
For this case, even if there is a filter `a2 IS NULL`, the `a1 IS NULL` cannot be generated for left join by rule `FlinkFilterJoinRule` and this filter cannot be pushed down to both MyTable1 and MyTable2.
## Brief change log
- Change rule `FlinkFilterJoinRule`
- Adding UT and IT
## Verifying this change
- Adding UT and IT
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? no docs
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] godfreyhe commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "godfreyhe (via GitHub)" <gi...@apache.org>.
godfreyhe commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1135047849
##########
flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/batch/sql/MultipleInputCreationTest.xml:
##########
@@ -136,11 +136,9 @@ LogicalProject(a=[$0], d=[$1], e=[$2], f=[$3], ny=[$4], a0=[$5], b=[$6], c=[$7])
<![CDATA[
MultipleInput(readOrder=[0,0,1], members=[\nNestedLoopJoin(joinType=[LeftOuterJoin], where=[(a = a0)], select=[a, d, e, f, ny, a0, b, c], build=[right])\n:- NestedLoopJoin(joinType=[LeftOuterJoin], where=[(a = d)], select=[a, d, e, f, ny], build=[right])\n: :- Calc(select=[a], where=[(a > 10)])\n: : +- [#3] BoundedStreamScan(table=[[default_catalog, default_database, chainable]], fields=[a])\n: +- [#2] Exchange(distribution=[broadcast])\n+- [#1] Exchange(distribution=[broadcast])\n])
:- Exchange(distribution=[broadcast])
-: +- Calc(select=[a, b, c], where=[(a > 10)])
Review Comment:
why the left side filters can not be pushed down ?
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
please also take care about `a2 = null`
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRuleTest.java:
##########
@@ -240,6 +240,21 @@ public void testLeftJoinWithAllFiltersFromWhere() {
"SELECT * FROM MyTable1 LEFT JOIN MyTable2 ON true WHERE b1 = b2 AND c1 = c2 AND a2 = 2 AND b2 > 10 AND COALESCE(c1, c2) <> '' ");
}
+ @Test
Review Comment:
please add some tests (including IT case) for inner joins
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
additional, less(or equal) than, greater (or equal) than a literal can also be supported
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] godfreyhe commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "godfreyhe (via GitHub)" <gi...@apache.org>.
godfreyhe commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1134883506
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
for left outer join, only the equal conditions from right side can be push to the left side. and vice versa for right outer join.
please add some non equal conditions (such as a2 <> 10 ) in the IT case
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #22049:
URL: https://github.com/apache/flink/pull/22049#issuecomment-1449496876
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "4b12337f38745fb12ab25339c2ccf90531935bc7",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "4b12337f38745fb12ab25339c2ccf90531935bc7",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 4b12337f38745fb12ab25339c2ccf90531935bc7 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] swuferhong commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "swuferhong (via GitHub)" <gi...@apache.org>.
swuferhong commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1135101054
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRuleTest.java:
##########
@@ -240,6 +240,21 @@ public void testLeftJoinWithAllFiltersFromWhere() {
"SELECT * FROM MyTable1 LEFT JOIN MyTable2 ON true WHERE b1 = b2 AND c1 = c2 AND a2 = 2 AND b2 > 10 AND COALESCE(c1, c2) <> '' ");
}
+ @Test
Review Comment:
Done!
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] godfreyhe closed pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "godfreyhe (via GitHub)" <gi...@apache.org>.
godfreyhe closed pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
URL: https://github.com/apache/flink/pull/22049
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] swuferhong commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "swuferhong (via GitHub)" <gi...@apache.org>.
swuferhong commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1135073462
##########
flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/batch/sql/MultipleInputCreationTest.xml:
##########
@@ -136,11 +136,9 @@ LogicalProject(a=[$0], d=[$1], e=[$2], f=[$3], ny=[$4], a0=[$5], b=[$6], c=[$7])
<![CDATA[
MultipleInput(readOrder=[0,0,1], members=[\nNestedLoopJoin(joinType=[LeftOuterJoin], where=[(a = a0)], select=[a, d, e, f, ny, a0, b, c], build=[right])\n:- NestedLoopJoin(joinType=[LeftOuterJoin], where=[(a = d)], select=[a, d, e, f, ny], build=[right])\n: :- Calc(select=[a], where=[(a > 10)])\n: : +- [#3] BoundedStreamScan(table=[[default_catalog, default_database, chainable]], fields=[a])\n: +- [#2] Exchange(distribution=[broadcast])\n+- [#1] Exchange(distribution=[broadcast])\n])
:- Exchange(distribution=[broadcast])
-: +- Calc(select=[a, b, c], where=[(a > 10)])
Review Comment:
> why the left side filters can not be pushed down ?
this case is :
`SELECT * FROM chainable
LEFT JOIN y ON chainable.a = y.d
LEFT JOIN t ON chainable.a = t.a
WHERE chainable.a > 10`
It will be push down to chainable, but don‘t push down to y and t.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] swuferhong commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "swuferhong (via GitHub)" <gi...@apache.org>.
swuferhong commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1134791918
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
Hi, @herunkang2018. For method FlinkFilterJoinRule#pushFiltersToAnotherSide, we only support Inner/left/Right join. So there is no need to judge the full outer join here.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] herunkang2018 commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "herunkang2018 (via GitHub)" <gi...@apache.org>.
herunkang2018 commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1134786876
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
if we need to check full outer join here?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] swuferhong commented on a diff in pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "swuferhong (via GitHub)" <gi...@apache.org>.
swuferhong commented on code in PR #22049:
URL: https://github.com/apache/flink/pull/22049#discussion_r1134947973
##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkFilterJoinRule.java:
##########
@@ -386,6 +387,21 @@ private void pushFiltersToAnotherSide(
}
}
+ private boolean isSuitableFilterToPush(RexNode filter, JoinRelType joinType) {
+ if (filter.isAlwaysTrue()) {
+ return false;
+ }
+ // For left/right outer join, we cannot push down IS_NULL filter to other side. Take left
+ // outer join as an example, If the join right side contains an IS_NULL filter, while we try
+ // to push it to the join left side and the left side have any other filter on this column,
+ // which will conflict and generate wrong plan.
+ if ((joinType == JoinRelType.LEFT || joinType == JoinRelType.RIGHT)
Review Comment:
> for left outer join, only the equal conditions from right side can be push to the left side. and vice versa for right outer join.
>
> please add some non equal conditions (such as a2 <> 10 ) in the IT case
Done!
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] swuferhong commented on pull request #22049: [FLINK-31273][table-planner] Fix left join with IS_NULL filter be wrongly pushed down and get wrong join results
Posted by "swuferhong (via GitHub)" <gi...@apache.org>.
swuferhong commented on PR #22049:
URL: https://github.com/apache/flink/pull/22049#issuecomment-1466306222
@flinkbot run azure
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org