mihaibudiu commented on code in PR #4691:
URL: https://github.com/apache/calcite/pull/4691#discussion_r2632065578
##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -634,7 +634,23 @@ public TrimResult trimFields(
RelOptUtil.InputFinder inputFinder =
new RelOptUtil.InputFinder(inputExtraFields, fieldsUsed);
conditionExpr.accept(inputFinder);
- final ImmutableBitSet inputFieldsUsed = inputFinder.build();
+
+ // Collect all the SubQueries in the filter condition.
+ List<RexSubQuery> subQueries = RexUtil.SubQueryCollector.collect(filter);
+ // Get all the correlationIds present in the SubQueries
+ Set<CorrelationId> correlationIds =
RelOptUtil.getVariablesUsed(subQueries);
+ ImmutableBitSet requiredColumns = ImmutableBitSet.of();
+ if (!correlationIds.isEmpty()) {
+ // Correlation columns are also needed by SubQueries, so add them to
inputFieldsUsed.
+ requiredColumns =
RelOptUtil.correlationColumns(correlationIds.iterator().next(), filter);
Review Comment:
If the plan is wrong it would be useful to have an issue about it.
The trimmer should convert legal plans to legal equivalent plans - otherwise
there is a bug in the trimmer as well.
--
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]