[fix](nereids) fix cte filter pushdown if the filters can be aggregated (#24489)
Current cte common filter extraction doesn't work if the filters can be aggregated, which will lead the common filter can't be pushed down inside cte. Consider the following case: with main as (select c1 from t1) select * from (select m1.* from main m1, main m2 where m1.c1 = m2.c1) abc where c1 = 1; The common c1=1 filter can't be pushed down. This pr fixed the original extraction logic from set to list to make the logic works, and this will also resolve the tpcds query4/11's pattern works well also.
This commit is contained in:
@ -145,10 +145,10 @@ public class RewriteCteChildren extends DefaultPlanRewriter<CascadesContext> imp
|
||||
Set<RelationId> consumerIds = cascadesContext.getCteIdToConsumers().get(cteId).stream()
|
||||
.map(LogicalCTEConsumer::getRelationId)
|
||||
.collect(Collectors.toSet());
|
||||
Set<Set<Expression>> filtersAboveEachConsumer = cascadesContext.getConsumerIdToFilters().entrySet().stream()
|
||||
List<Set<Expression>> filtersAboveEachConsumer = cascadesContext.getConsumerIdToFilters().entrySet().stream()
|
||||
.filter(kv -> consumerIds.contains(kv.getKey()))
|
||||
.map(Entry::getValue)
|
||||
.collect(Collectors.toSet());
|
||||
.collect(Collectors.toList());
|
||||
Set<Expression> someone = filtersAboveEachConsumer.stream().findFirst().orElse(null);
|
||||
if (someone == null) {
|
||||
return child;
|
||||
@ -156,11 +156,12 @@ public class RewriteCteChildren extends DefaultPlanRewriter<CascadesContext> imp
|
||||
int filterSize = cascadesContext.getCteIdToConsumers().get(cteId).size();
|
||||
Set<Expression> conjuncts = new HashSet<>();
|
||||
for (Expression f : someone) {
|
||||
int matchCount = 1;
|
||||
int matchCount = 0;
|
||||
Set<SlotReference> slots = f.collect(e -> e instanceof SlotReference);
|
||||
Set<Expression> mightBeJoined = new HashSet<>();
|
||||
for (Set<Expression> another : filtersAboveEachConsumer) {
|
||||
if (another.equals(someone)) {
|
||||
matchCount++;
|
||||
continue;
|
||||
}
|
||||
Set<Expression> matched = new HashSet<>();
|
||||
|
||||
Reference in New Issue
Block a user