mihaibudiu commented on code in PR #5366:
URL: https://github.com/apache/calcite/pull/5366#discussion_r4397802260
##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -967,24 +967,34 @@ private static void matchProject(SubQueryRemoveRule rule,
final Project project = call.rel(0);
final Set<CorrelationId> projectVariablesSet = project.getVariablesSet();
final RelBuilder builder = call.builder();
- final RexSubQuery e =
- requireNonNull(RexUtil.SubQueryFinder.find(project.getProjects()));
- final RelOptUtil.Logic logic =
- LogicVisitor.find(RelOptUtil.Logic.TRUE_FALSE_UNKNOWN,
- project.getProjects(), e);
builder.push(project.getInput());
- final int fieldCount = builder.peek().getRowType().getFieldCount();
- final Set<CorrelationId> variablesSet =
- RelOptUtil.getVariablesUsed(e.rel);
- if (!projectVariablesSet.isEmpty()) {
+ // Rewrite all sub-queries in one call, as matchFilter does. If only one
+ // were rewritten per call, the Project created for the remaining ones
+ // would no longer define the correlation variables that they use, and a
+ // later call could not tell this Project's variables from those of an
+ // outer scope.
+ int count = 0;
+ List<RexNode> projects = project.getProjects();
+ while (true) {
+ final RexSubQuery e = RexUtil.SubQueryFinder.find(projects);
Review Comment:
the other PR attacking a similar problem #5356 uses a new visitor which
finds the innermost subquery first.
--
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]