Skip to content

Commit

Permalink
[fix](Nereids) should push project through limit after eliminate unio…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
morrySnow authored Aug 22, 2024
1 parent ca9e50e commit 83acdc1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("push_limit_with_eliminate_union") {
// this should not failed for [INTERNAL_ERROR]VSlotRef have invalid slot id
sql """(select 1 limit 0 union all select count() + 1) limit 1;"""
}

0 comments on commit 83acdc1

Please sign in to comment.