Skip to content

Commit

Permalink
[fix](Nereids) eliminate union should execute before limit push down
Browse files Browse the repository at this point in the history
other wise:

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 committed Aug 21, 2024
1 parent 93081b9 commit f00331c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,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 @@ -422,7 +423,11 @@ 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(),
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 f00331c

Please sign in to comment.