This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new af94b060175 [fix](nereids) mv selection should only consider visible
indexes (#38148)
af94b060175 is described below
commit af94b060175c9edd26c52ff9c4ecb5347635fed2
Author: starocean999 <[email protected]>
AuthorDate: Tue Jul 23 16:35:47 2024 +0800
[fix](nereids) mv selection should only consider visible indexes (#38148)
the indexes in olap table are not always visible. Sometimes, schema
change will introduce invisible index into olap table. And we should
only use getVisibleIndexIdToMeta() to get visible indexes as candidates
for mv selection.
---
.../mv/InitMaterializationContextHook.java | 19 +++++++++----------
.../nereids_syntax_p0/mv/ut/distinctQuery.groovy | 1 +
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
index 77869e76ff7..c48303dbf0b 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java
@@ -168,13 +168,12 @@ public class InitMaterializationContextHook implements
PlannerHook {
for (Column column : olapTable.getFullSchema()) {
keyCount += column.isKey() ? 1 : 0;
}
- for (Map.Entry<String, Long> entry :
olapTable.getIndexNameToId().entrySet()) {
- long indexId = entry.getValue();
+ for (Map.Entry<Long, MaterializedIndexMeta> entry :
olapTable.getVisibleIndexIdToMeta().entrySet()) {
+ long indexId = entry.getKey();
try {
- // when doing schema change, a shadow index would be created
and put together with mv indexes
- // we must roll out these unexpected shadow indexes here
- if (indexId != baseIndexId &&
!olapTable.isShadowIndex(indexId)) {
- MaterializedIndexMeta meta =
olapTable.getIndexMetaByIndexId(entry.getValue());
+ if (indexId != baseIndexId) {
+ MaterializedIndexMeta meta = entry.getValue();
+ String indexName = olapTable.getIndexNameById(indexId);
String createMvSql;
if (meta.getDefineStmt() != null) {
// get the original create mv sql
@@ -183,11 +182,11 @@ public class InitMaterializationContextHook implements
PlannerHook {
// it's rollup, need assemble create mv sql manually
if (olapTable.getKeysType() == KeysType.AGG_KEYS) {
createMvSql =
assembleCreateMvSqlForAggTable(olapTable.getQualifiedName(),
- entry.getKey(), meta.getSchema(false),
keyCount);
+ indexName, meta.getSchema(false),
keyCount);
} else {
createMvSql =
assembleCreateMvSqlForDupOrUniqueTable(olapTable.getQualifiedName(),
- entry.getKey(),
meta.getSchema(false));
+ indexName, meta.getSchema(false));
}
}
if (createMvSql != null) {
@@ -200,10 +199,10 @@ public class InitMaterializationContextHook implements
PlannerHook {
MTMVCache mtmvCache =
MaterializedViewUtils.createMTMVCache(querySql.get(),
cascadesContext.getConnectContext());
contexts.add(new
SyncMaterializationContext(mtmvCache.getLogicalPlan(),
- mtmvCache.getOriginalPlan(), olapTable,
meta.getIndexId(), entry.getKey(),
+ mtmvCache.getOriginalPlan(), olapTable,
meta.getIndexId(), indexName,
cascadesContext, mtmvCache.getStatistics()));
} else {
- LOG.warn(String.format("can't assemble create mv sql
for index ", entry.getKey()));
+ LOG.warn(String.format("can't assemble create mv sql
for index ", indexName));
}
}
} catch (Exception exception) {
diff --git
a/regression-test/suites/nereids_syntax_p0/mv/ut/distinctQuery.groovy
b/regression-test/suites/nereids_syntax_p0/mv/ut/distinctQuery.groovy
index d4b9fde26e6..baffcb8ba48 100644
--- a/regression-test/suites/nereids_syntax_p0/mv/ut/distinctQuery.groovy
+++ b/regression-test/suites/nereids_syntax_p0/mv/ut/distinctQuery.groovy
@@ -42,6 +42,7 @@ suite ("distinctQuery") {
createMV("create materialized view distinctQuery_mv2 as select empid,
deptno, count(salary) from distinctQuery group by empid, deptno;")
sql """insert into distinctQuery values("2020-01-01",1,"a",1,1,1);"""
+ sql """insert into distinctQuery values("2020-01-01",2,"a",1,1,1);"""
sql "analyze table distinctQuery with sync;"
sql """set enable_stats=false;"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]