Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](nereids)mv selection should only consider visible indexes #38148

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ private List<SyncMaterializationContext> createSyncMvContexts(OlapTable olapTabl
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
Expand All @@ -159,11 +158,11 @@ private List<SyncMaterializationContext> createSyncMvContexts(OlapTable olapTabl
// 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) {
Expand All @@ -176,10 +175,10 @@ private List<SyncMaterializationContext> createSyncMvContexts(OlapTable olapTabl
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"""
Expand Down
Loading