[fix](Nereids) should push project through limit after eliminate union node (#39640) (#39755)

pick from master #39640

otherwise:

push limit through union could generate plan:

limit
+-- union
    |-- limit
    |   +-- empty relation
    +-- limit
        +-- project

and then eliminate union will generate plan:

+-- limit
    +-  project
        +-- limit
            +-- project

it could not be processed by tranlator correctly
This commit is contained in:
morrySnow
2024-08-22 13:57:39 +08:00
committed by GitHub
parent ca9e50e49d
commit 83acdc14f4
2 changed files with 33 additions and 1 deletions

View File

@ -114,6 +114,7 @@ import org.apache.doris.nereids.rules.rewrite.PushDownFilterThroughProject;
import org.apache.doris.nereids.rules.rewrite.PushDownLimit;
import org.apache.doris.nereids.rules.rewrite.PushDownLimitDistinctThroughJoin;
import org.apache.doris.nereids.rules.rewrite.PushDownLimitDistinctThroughUnion;
import org.apache.doris.nereids.rules.rewrite.PushDownProjectThroughLimit;
import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughJoin;
import org.apache.doris.nereids.rules.rewrite.PushDownTopNDistinctThroughUnion;
import org.apache.doris.nereids.rules.rewrite.PushDownTopNThroughJoin;
@ -416,7 +417,17 @@ public class Rewriter extends AbstractBatchJobExecutor {
topic("eliminate",
// SORT_PRUNING should be applied after mergeLimit
custom(RuleType.ELIMINATE_SORT, EliminateSort::new),
bottomUp(new EliminateEmptyRelation())
bottomUp(
new EliminateEmptyRelation(),
// after eliminate empty relation under union, we could get
// limit
// +-- project
// +-- limit
// + project
// so, we need push project through limit to satisfy translator's assumptions
new PushDownFilterThroughProject(),
new PushDownProjectThroughLimit(),
new MergeProjects())
),
topic("agg rewrite",
// these rules should be put after mv optimization to avoid mv matching fail