silundong commented on code in PR #4691:
URL: https://github.com/apache/calcite/pull/4691#discussion_r2633232249
##########
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:
> This is a relatively complex SQL query, and the current PR likely does not
address this.
This is indeed quite complex. As long as it doesn't lead to missing any
columns, it's fine.
--
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]