diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughProject.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughProject.java index d40e485ca03f282..80a70d7e73292de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughProject.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownFilterThroughProject.java @@ -30,11 +30,14 @@ import org.apache.doris.nereids.trees.plans.logical.LogicalProject; import org.apache.doris.nereids.util.ExpressionUtils; import org.apache.doris.nereids.util.PlanUtils; +import org.apache.doris.qe.ConnectContext; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -84,8 +87,15 @@ private static Plan pushDownFilterThroughProject(LogicalFilter) project.withChildren(new LogicalFilter<>( - ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second), project.getAliasToProducer()), + Set conjuncts; + if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableCompressMaterialize) { + conjuncts = ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second), + project.getAliasToProducer()); + } else { + conjuncts = ExpressionUtils.replace(splitConjuncts.second, + project.getAliasToProducer()); + } + project = (LogicalProject) project.withChildren(new LogicalFilter<>(conjuncts, project.child())); return PlanUtils.filterOrSelf(splitConjuncts.first, project); } @@ -101,10 +111,17 @@ private static Plan pushDownFilterThroughLimitProject( if (splitConjuncts.second.isEmpty()) { return null; } + Set conjuncts; + if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableCompressMaterialize) { + conjuncts = ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second), + project.getAliasToProducer()); + } else { + conjuncts = ExpressionUtils.replace(splitConjuncts.second, + project.getAliasToProducer()); + } project = project.withProjectsAndChild(project.getProjects(), new LogicalFilter<>( - ExpressionUtils.replace(eliminateDecodeAndEncode(splitConjuncts.second), - project.getAliasToProducer()), + conjuncts, limit.withChildren(project.child()))); return PlanUtils.filterOrSelf(splitConjuncts.first, project); } @@ -125,9 +142,12 @@ private static Pair, Set> splitConjunctsByChildOutpu } private static Set eliminateDecodeAndEncode(Set expressions) { - return expressions.stream() - .map(PushDownFilterThroughProject::eliminateDecodeAndEncode) - .collect(Collectors.toSet()); + LinkedHashSet eliminated = new LinkedHashSet(); + // keep expression order + for (Expression expression : expressions) { + eliminated.add(eliminateDecodeAndEncode(expression)); + } + return eliminated; } private static Expression eliminateDecodeAndEncode(Expression expression) {