Skip to content

Commit

Permalink
[Fix](MV) query not hit partition in original planner (apache#38565)
Browse files Browse the repository at this point in the history
this issue seems introduced by apache#21533

Fix issue that query not hit partition in original planner, which will
cause serve performance degradation.
  • Loading branch information
GoGoWen authored Aug 14, 2024
1 parent 9e9bdfb commit f370e35
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.PartitionKey;
import org.apache.doris.common.Config;
import org.apache.doris.qe.ConnectContext;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -79,10 +80,13 @@ public Collection<Long> prune(int columnId, PartitionKey hashKey, int complex) {
return Lists.newArrayList(bucketsList.get((int) ((hashValue & 0xffffffff) % hashMod)));
}
Column keyColumn = distributionColumns.get(columnId);
String columnName = isBaseIndexSelected ? keyColumn.getName()
: org.apache.doris.nereids.rules.rewrite.mv.AbstractSelectMaterializedIndexRule
String columnName = keyColumn.getName();
if (!isBaseIndexSelected && ConnectContext.get().getSessionVariable().isEnableNereidsPlanner()) {
columnName = org.apache.doris.nereids.rules.rewrite.mv.AbstractSelectMaterializedIndexRule
.normalizeName(
CreateMaterializedViewStmt.mvColumnBuilder(keyColumn.getName()));
}

PartitionColumnFilter filter = distributionColumnFilters.get(columnName);
if (null == filter) {
// no filter in this column, no partition Key
Expand Down
52 changes: 52 additions & 0 deletions regression-test/suites/rollup_p0/test_rollup_prune_tablet.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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("test_rollup_prune_tablet") {
sql "SET enable_nereids_planner=false"

sql "DROP TABLE IF EXISTS test_prune_tablet_t2"
sql """
CREATE TABLE `test_prune_tablet_t2` (
`id` INT NULL,
`c1` BOOLEAN NULL,
`id2` BIGINT NULL,
`id3` BIGINT NULL,
`id4` BIGINT NULL
) distributed by hash(id) BUCKETS 16 properties('replication_num'='1');
"""

createMV( """
alter table test_prune_tablet_t2 add rollup example_rollup_index(c1,id);
""")

sql """insert into test_prune_tablet_t2 values
(1,0,1,1,1),
(2,0,2,2,2),
(3,0,3,3,3),
(4,0,4,4,4),
(5,0,5,5,5),
(6,0,6,6,6),
(7,0,7,7,7);"""

explain {
sql("select id,sum(c1) from test_prune_tablet_t2 where c1=0 and id = 3 group by id;")
contains "example_rollup_index"
contains "tablets=1/16"
}

sql "DROP TABLE IF EXISTS test_prune_tablet_t2"
}

0 comments on commit f370e35

Please sign in to comment.