From 5a13c7596a2619866447283ecc761835a88bbda8 Mon Sep 17 00:00:00 2001 From: starocean999 <40539150+starocean999@users.noreply.github.com> Date: Mon, 29 Jan 2024 10:50:17 +0800 Subject: [PATCH] [fix](nereids)should normalize mv column's name before matching prefix keys (#27464) --- .../AbstractSelectMaterializedIndexRule.java | 4 +- .../mv/newMv/unique_mv.groovy | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/AbstractSelectMaterializedIndexRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/AbstractSelectMaterializedIndexRule.java index 7cd63642b3..8ecabcd891 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/AbstractSelectMaterializedIndexRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/mv/AbstractSelectMaterializedIndexRule.java @@ -358,9 +358,9 @@ public abstract class AbstractSelectMaterializedIndexRule { Set nonEqualColNames) { int matchCount = 0; for (Column column : table.getSchemaByIndexId(index.getId())) { - if (equalColNames.contains(column.getName())) { + if (equalColNames.contains(normalizeName(column.getNameWithoutMvPrefix()))) { matchCount++; - } else if (nonEqualColNames.contains(column.getName())) { + } else if (nonEqualColNames.contains(normalizeName(column.getNameWithoutMvPrefix()))) { // un-equivalence predicate's columns can match only first column in index. matchCount++; break; diff --git a/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy b/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy new file mode 100644 index 0000000000..c932dd4723 --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/mv/newMv/unique_mv.groovy @@ -0,0 +1,48 @@ +// 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 ("unique_mv") { + sql """set enable_nereids_planner=true;""" + sql """set enable_fallback_to_original_planner=false""" + sql """ DROP TABLE IF EXISTS c5816_t; """ + + sql """ + create table c5816_t( + org_id bigint, + campaign_id bigint, + call_time datetime, + id bigint, + call_uuid varchar(128), + aa bigint + ) + unique KEY(org_id,campaign_id,call_time,id,call_uuid) + DISTRIBUTED BY HASH(id) BUCKETS 1 + PROPERTIES + ( + "replication_num" = "1", + "enable_unique_key_merge_on_write" = "false" + ); + """ + + createMV("""create materialized view mv_1 as select call_uuid,org_id,call_time,id,campaign_id,aa from c5816_t""") + sql """insert into c5816_t values (1,2,"2023-11-20 00:00:00",4,"adc",12);""" + + explain { + sql("SELECT * FROM c5816_t WHERE call_uuid='adc';") + contains "(mv_1)" + } +}