From 2625ff331f47b96382bf458f612231e95d6e6f20 Mon Sep 17 00:00:00 2001 From: Kevin Cai Date: Wed, 13 May 2026 11:08:50 +0800 Subject: [PATCH 1/5] [BugFix] Relax DB lock to intensive path in qe/ read-only paths (#73067) Signed-off-by: Kevin Cai (cherry picked from commit c15972b5ad3fa8e7d7ed95092ffad17d5e065441) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java --- .../com/starrocks/qe/ConnectProcessor.java | 34 +++++-- .../java/com/starrocks/qe/ShowExecutor.java | 92 +++++++++++++++++-- 2 files changed, 113 insertions(+), 13 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java index d0c0ff9a81b6d2..a053f6626c485f 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java @@ -580,17 +580,37 @@ private void handleFieldList() throws IOException { ctx.getState().setError("Unknown database(" + ctx.getDatabase() + ")"); return; } - Locker locker = new Locker(); - locker.lockDatabase(db.getId(), LockType.READ); + // Internal catalog: lookup resolves to Database.nameToTable (a ConcurrentHashMap, + // lock-free safe). External catalog: lookup routes through ConnectorMetadata, whose + // concurrency is connector-managed. No FE write path takes the LockManager lock on + // external db ids, so the intensive lock acquired below is harmless overhead on + // external catalogs and the unlocked lookup changes nothing for them. + Table table; try { - // we should get table through metadata manager - Table table = ctx.getGlobalStateMgr().getMetadataMgr().getTable( + table = ctx.getGlobalStateMgr().getMetadataMgr().getTable( ctx, ctx.getCurrentCatalog(), ctx.getDatabase(), tableName); - if (table == null) { + } catch (StarRocksConnectorException e) { + LOG.error("errors happened when getting table {}", tableName, e); + ctx.getState().setEof(); + return; + } + if (table == null) { + ctx.getState().setError("Unknown table(" + tableName + ")"); + return; + } + + Locker locker = new Locker(); + locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); + try { + // Revalidate by name to detect concurrent DROP/RENAME between unlocked lookup + // and lock acquisition. The table id is stable, so id-based revalidation would + // miss a RENAME that re-binds the name to a different table. Internal-catalog + // only: LocalMetastore doesn't track connector tables, so a re-fetch for + // external catalogs would always return null and falsely fail. + if (db.getCatalogName() == null && db.getTable(tableName) != table) { ctx.getState().setError("Unknown table(" + tableName + ")"); return; } - MysqlSerializer serializer = ctx.getSerializer(); MysqlChannel channel = ctx.getMysqlChannel(); @@ -605,7 +625,7 @@ private void handleFieldList() throws IOException { } catch (StarRocksConnectorException e) { LOG.error("errors happened when getting table {}", tableName, e); } finally { - locker.unLockDatabase(db.getId(), LockType.READ); + locker.unLockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); } ctx.getState().setEof(); } diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index 9a1deadd65fd79..eb8cb9388c2ed3 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -743,6 +743,7 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(showStmt.getDb()); MetaUtils.checkDbNullAndReport(db, showStmt.getDb()); List> rows = Lists.newArrayList(); +<<<<<<< HEAD Locker locker = new Locker(); locker.lockDatabase(db.getId(), LockType.READ); try { @@ -775,14 +776,72 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm .addColumn(new Column("Create Materialized View", ScalarType.createVarchar(30))) .build(); return new ShowResultSet(showResultSetMetaData, rows); +======= + TableName tableName = new TableName(showStmt.getCatalogName(), showStmt.getDb(), showStmt.getTable()); + // Lookup is ConcurrentHashMap-backed (Database.nameToTable) for internal catalog and + // throws SemanticException if the table is missing, so it is safe outside the lock. + Table table = MetaUtils.getSessionAwareTable(connectContext, db, tableName); + // TODO(sync-mv): the (table == null) branch below is currently unreachable - + // MetaUtils.getSessionAwareTable throws SemanticException on miss rather than + // returning null (since #43162, "temporary table part-1"), so the sync-MV + // fallback never runs. As a side effect, SHOW CREATE MATERIALIZED VIEW + // has been broken since that change (sync MVs live as MaterializedIndexMeta + // inside an OLAP table, not as separately-registered Tables, so they are missed + // by the throwing lookup above). The fallback is kept here as a marker until a + // follow-up commit reworks the lookup to make this path reachable. When that + // happens, the iteration must run under DB READ (or per-table READ) - it reads + // HashMap-backed OlapTable index metadata which is mutated by concurrent + // ALTER/rollup. Today the unlocked iteration is harmless because it never + // executes. + if (table == null) { + if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) { + ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); + } else { + // For Sync Materialized View, it is a mv index inside OLAP table, + // so we can not get it from database. + for (Table tbl : GlobalStateMgr.getCurrentState().getLocalMetastore().getTables(db.getId())) { + if (tbl.getType() == Table.TableType.OLAP) { + OlapTable olapTable = (OlapTable) tbl; + List visibleMaterializedViews = + olapTable.getVisibleIndexMetas(); + for (MaterializedIndexMeta mvMeta : visibleMaterializedViews) { + if (olapTable.getIndexNameByMetaId(mvMeta.getIndexMetaId()).equals(showStmt.getTable())) { + if (mvMeta.getOriginStmt() == null) { + String mvName = olapTable.getIndexNameByMetaId(mvMeta.getIndexMetaId()); + rows.add(Lists.newArrayList(showStmt.getTable(), + ShowMaterializedViewStatus.buildCreateMVSql(olapTable, + mvName, mvMeta), "utf8", "utf8_general_ci")); + } else { + rows.add(Lists.newArrayList(showStmt.getTable(), mvMeta.getOriginStmt(), + "utf8", "utf8_general_ci")); +>>>>>>> c15972b5ad ([BugFix] Relax DB lock to intensive path in qe/ read-only paths (#73067)) } + + ShowResultSetMetaData showResultSetMetaData = ShowResultSetMetaData.builder() + .addColumn(new Column("Materialized View", + TypeFactory.createVarcharType(20))) + .addColumn(new Column("Create Materialized View", + TypeFactory.createVarcharType(30))) + .build(); + return new ShowResultSet(showResultSetMetaData, rows); } } } - ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } + ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); + } + } + Locker locker = new Locker(); + locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); + try { + // Revalidate by name to detect concurrent DROP/RENAME between unlocked lookup + // and lock acquisition. The table id is stable for a given Table object, so an + // id-based check would miss a RENAME that re-binds the name to a different + // (or no) table; revalidate via the same lookup path so both regular and + // temporary tables are handled correctly. + if (MetaUtils.getSessionAwareTable(connectContext, db, tableName) != table) { + ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } - List createTableStmt = Lists.newArrayList(); AstToStringBuilder.getDdlStmt(table, createTableStmt, null, null, false, true /* hide password */); if (createTableStmt.isEmpty()) { @@ -835,7 +894,7 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm return new ShowResultSet(showResultMetaFactory.getMetadata(showStmt), rows); } } finally { - locker.unLockDatabase(db.getId(), LockType.READ); + locker.unLockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); } } @@ -1713,7 +1772,7 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC dbName = db.getFullName(); Locker locker = new Locker(); - locker.lockDatabase(db.getId(), LockType.READ); + locker.lockTableWithIntensiveDbLock(db.getId(), tableId, LockType.READ); try { Table table = GlobalStateMgr.getCurrentState().getLocalMetastore().getTable(db.getId(), tableId); if (!(table instanceof OlapTable)) { @@ -1774,7 +1833,7 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC } } finally { - locker.unLockDatabase(db.getId(), LockType.READ); + locker.unLockTableWithIntensiveDbLock(db.getId(), tableId, LockType.READ); } } while (false); @@ -1788,6 +1847,7 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC Database db = globalStateMgr.getLocalMetastore().getDb(statement.getDbName()); MetaUtils.checkDbNullAndReport(db, statement.getDbName()); +<<<<<<< HEAD Locker locker = new Locker(); locker.lockDatabase(db.getId(), LockType.READ); try { @@ -1799,7 +1859,27 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC if (!table.isNativeTableOrMaterializedView()) { ErrorReport.reportSemanticException(ErrorCode.ERR_NOT_OLAP_TABLE, statement.getTableName()); } +======= + // Lookup is ConcurrentHashMap-backed for the internal catalog and throws on missing + // table, so it is safe outside the lock. + TableName tableName = new TableName(tableRef.getCatalogName(), tableRef.getDbName(), + tableRef.getTableName()); + Table table = MetaUtils.getSessionAwareTable(context, db, tableName); + if (!table.isNativeTableOrMaterializedView()) { + ErrorReport.reportSemanticException(ErrorCode.ERR_NOT_OLAP_TABLE, statement.getTableName()); + } +>>>>>>> c15972b5ad ([BugFix] Relax DB lock to intensive path in qe/ read-only paths (#73067)) + Locker locker = new Locker(); + locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); + try { + // Revalidate by name to detect concurrent DROP/RENAME between unlocked lookup + // and lock acquisition. Id-based check would miss a RENAME that re-binds the + // name to a different table; re-running the same lookup catches that. + if (MetaUtils.getSessionAwareTable(context, db, tableName) != table) { + ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, + statement.getTableName()); + } Pair privResult = Authorizer.checkPrivForShowTablet( context, db.getFullName(), table); if (!privResult.first) { @@ -1894,7 +1974,7 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC rows.add(oneTablet); } } finally { - locker.unLockDatabase(db.getId(), LockType.READ); + locker.unLockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); } } From 4269e8355f30ad80821649b8cf3f603627237ee9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 03:24:16 +0000 Subject: [PATCH 2/5] fix: resolve ShowExecutor backport conflict minimally Agent-Logs-Url: https://github.com/StarRocks/starrocks/sessions/d259b835-cf31-40c2-b812-8e47115ec482 Co-authored-by: kevincai <771299+kevincai@users.noreply.github.com> --- .../java/com/starrocks/qe/ShowExecutor.java | 88 ++----------------- 1 file changed, 6 insertions(+), 82 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index eb8cb9388c2ed3..3bfd80e9e394d8 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -743,56 +743,8 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(showStmt.getDb()); MetaUtils.checkDbNullAndReport(db, showStmt.getDb()); List> rows = Lists.newArrayList(); -<<<<<<< HEAD - Locker locker = new Locker(); - locker.lockDatabase(db.getId(), LockType.READ); - try { - Table table = MetaUtils.getSessionAwareTable(connectContext, db, showStmt.getTbl()); - if (table == null) { - if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) { - ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); - } else { - // For Sync Materialized View, it is a mv index inside OLAP table, - // so we can not get it from database. - for (Table tbl : GlobalStateMgr.getCurrentState().getLocalMetastore().getTables(db.getId())) { - if (tbl.getType() == Table.TableType.OLAP) { - OlapTable olapTable = (OlapTable) tbl; - List visibleMaterializedViews = - olapTable.getVisibleIndexMetas(); - for (MaterializedIndexMeta mvMeta : visibleMaterializedViews) { - if (olapTable.getIndexNameById(mvMeta.getIndexId()).equals(showStmt.getTable())) { - if (mvMeta.getOriginStmt() == null) { - String mvName = olapTable.getIndexNameById(mvMeta.getIndexId()); - rows.add(Lists.newArrayList(showStmt.getTable(), - ShowMaterializedViewStatus.buildCreateMVSql(olapTable, - mvName, mvMeta), "utf8", "utf8_general_ci")); - } else { - rows.add(Lists.newArrayList(showStmt.getTable(), mvMeta.getOriginStmt(), - "utf8", "utf8_general_ci")); - } - - ShowResultSetMetaData showResultSetMetaData = ShowResultSetMetaData.builder() - .addColumn(new Column("Materialized View", ScalarType.createVarchar(20))) - .addColumn(new Column("Create Materialized View", ScalarType.createVarchar(30))) - .build(); - return new ShowResultSet(showResultSetMetaData, rows); -======= - TableName tableName = new TableName(showStmt.getCatalogName(), showStmt.getDb(), showStmt.getTable()); - // Lookup is ConcurrentHashMap-backed (Database.nameToTable) for internal catalog and - // throws SemanticException if the table is missing, so it is safe outside the lock. + TableName tableName = showStmt.getTbl(); Table table = MetaUtils.getSessionAwareTable(connectContext, db, tableName); - // TODO(sync-mv): the (table == null) branch below is currently unreachable - - // MetaUtils.getSessionAwareTable throws SemanticException on miss rather than - // returning null (since #43162, "temporary table part-1"), so the sync-MV - // fallback never runs. As a side effect, SHOW CREATE MATERIALIZED VIEW - // has been broken since that change (sync MVs live as MaterializedIndexMeta - // inside an OLAP table, not as separately-registered Tables, so they are missed - // by the throwing lookup above). The fallback is kept here as a marker until a - // follow-up commit reworks the lookup to make this path reachable. When that - // happens, the iteration must run under DB READ (or per-table READ) - it reads - // HashMap-backed OlapTable index metadata which is mutated by concurrent - // ALTER/rollup. Today the unlocked iteration is harmless because it never - // executes. if (table == null) { if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) { ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); @@ -805,23 +757,20 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm List visibleMaterializedViews = olapTable.getVisibleIndexMetas(); for (MaterializedIndexMeta mvMeta : visibleMaterializedViews) { - if (olapTable.getIndexNameByMetaId(mvMeta.getIndexMetaId()).equals(showStmt.getTable())) { + if (olapTable.getIndexNameById(mvMeta.getIndexId()).equals(showStmt.getTable())) { if (mvMeta.getOriginStmt() == null) { - String mvName = olapTable.getIndexNameByMetaId(mvMeta.getIndexMetaId()); + String mvName = olapTable.getIndexNameById(mvMeta.getIndexId()); rows.add(Lists.newArrayList(showStmt.getTable(), ShowMaterializedViewStatus.buildCreateMVSql(olapTable, mvName, mvMeta), "utf8", "utf8_general_ci")); } else { rows.add(Lists.newArrayList(showStmt.getTable(), mvMeta.getOriginStmt(), "utf8", "utf8_general_ci")); ->>>>>>> c15972b5ad ([BugFix] Relax DB lock to intensive path in qe/ read-only paths (#73067)) } ShowResultSetMetaData showResultSetMetaData = ShowResultSetMetaData.builder() - .addColumn(new Column("Materialized View", - TypeFactory.createVarcharType(20))) - .addColumn(new Column("Create Materialized View", - TypeFactory.createVarcharType(30))) + .addColumn(new Column("Materialized View", ScalarType.createVarchar(20))) + .addColumn(new Column("Create Materialized View", ScalarType.createVarchar(30))) .build(); return new ShowResultSet(showResultSetMetaData, rows); } @@ -834,11 +783,6 @@ >>>>>>> c15972b5ad ([BugFix] Relax DB lock to intensive path in qe/ read-only pa Locker locker = new Locker(); locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); try { - // Revalidate by name to detect concurrent DROP/RENAME between unlocked lookup - // and lock acquisition. The table id is stable for a given Table object, so an - // id-based check would miss a RENAME that re-binds the name to a different - // (or no) table; revalidate via the same lookup path so both regular and - // temporary tables are handled correctly. if (MetaUtils.getSessionAwareTable(connectContext, db, tableName) != table) { ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } @@ -1847,35 +1791,15 @@ public ShowResultSet visitShowTabletStatement(ShowTabletStmt statement, ConnectC Database db = globalStateMgr.getLocalMetastore().getDb(statement.getDbName()); MetaUtils.checkDbNullAndReport(db, statement.getDbName()); -<<<<<<< HEAD - Locker locker = new Locker(); - locker.lockDatabase(db.getId(), LockType.READ); - try { - Table table = MetaUtils.getSessionAwareTable( - context, db, new TableName(statement.getDbName(), statement.getTableName())); - if (table == null) { - ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, statement.getTableName()); - } - if (!table.isNativeTableOrMaterializedView()) { - ErrorReport.reportSemanticException(ErrorCode.ERR_NOT_OLAP_TABLE, statement.getTableName()); - } -======= - // Lookup is ConcurrentHashMap-backed for the internal catalog and throws on missing - // table, so it is safe outside the lock. - TableName tableName = new TableName(tableRef.getCatalogName(), tableRef.getDbName(), - tableRef.getTableName()); + TableName tableName = new TableName(statement.getDbName(), statement.getTableName()); Table table = MetaUtils.getSessionAwareTable(context, db, tableName); if (!table.isNativeTableOrMaterializedView()) { ErrorReport.reportSemanticException(ErrorCode.ERR_NOT_OLAP_TABLE, statement.getTableName()); } ->>>>>>> c15972b5ad ([BugFix] Relax DB lock to intensive path in qe/ read-only paths (#73067)) Locker locker = new Locker(); locker.lockTableWithIntensiveDbLock(db.getId(), table.getId(), LockType.READ); try { - // Revalidate by name to detect concurrent DROP/RENAME between unlocked lookup - // and lock acquisition. Id-based check would miss a RENAME that re-binds the - // name to a different table; re-running the same lookup catches that. if (MetaUtils.getSessionAwareTable(context, db, tableName) != table) { ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, statement.getTableName()); From eef70060c15aaadab982537f629e0f42e2903100 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 03:25:09 +0000 Subject: [PATCH 3/5] fix: guard sync mv fallback during conflict resolution Agent-Logs-Url: https://github.com/StarRocks/starrocks/sessions/d259b835-cf31-40c2-b812-8e47115ec482 Co-authored-by: kevincai <771299+kevincai@users.noreply.github.com> --- .../java/com/starrocks/qe/ShowExecutor.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index 3bfd80e9e394d8..1f3d7ea36df125 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -743,39 +743,46 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(showStmt.getDb()); MetaUtils.checkDbNullAndReport(db, showStmt.getDb()); List> rows = Lists.newArrayList(); - TableName tableName = showStmt.getTbl(); + TableName tableName = new TableName(showStmt.getCatalogName(), showStmt.getDb(), showStmt.getTable()); Table table = MetaUtils.getSessionAwareTable(connectContext, db, tableName); if (table == null) { if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) { ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } else { - // For Sync Materialized View, it is a mv index inside OLAP table, - // so we can not get it from database. - for (Table tbl : GlobalStateMgr.getCurrentState().getLocalMetastore().getTables(db.getId())) { - if (tbl.getType() == Table.TableType.OLAP) { - OlapTable olapTable = (OlapTable) tbl; - List visibleMaterializedViews = - olapTable.getVisibleIndexMetas(); - for (MaterializedIndexMeta mvMeta : visibleMaterializedViews) { - if (olapTable.getIndexNameById(mvMeta.getIndexId()).equals(showStmt.getTable())) { - if (mvMeta.getOriginStmt() == null) { - String mvName = olapTable.getIndexNameById(mvMeta.getIndexId()); - rows.add(Lists.newArrayList(showStmt.getTable(), - ShowMaterializedViewStatus.buildCreateMVSql(olapTable, - mvName, mvMeta), "utf8", "utf8_general_ci")); - } else { - rows.add(Lists.newArrayList(showStmt.getTable(), mvMeta.getOriginStmt(), - "utf8", "utf8_general_ci")); - } + Locker locker = new Locker(); + locker.lockDatabase(db.getId(), LockType.READ); + try { + // For Sync Materialized View, it is a mv index inside OLAP table, + // so we can not get it from database. + for (Table tbl : GlobalStateMgr.getCurrentState().getLocalMetastore().getTables(db.getId())) { + if (tbl.getType() == Table.TableType.OLAP) { + OlapTable olapTable = (OlapTable) tbl; + List visibleMaterializedViews = + olapTable.getVisibleIndexMetas(); + for (MaterializedIndexMeta mvMeta : visibleMaterializedViews) { + if (olapTable.getIndexNameById(mvMeta.getIndexId()).equals(showStmt.getTable())) { + if (mvMeta.getOriginStmt() == null) { + String mvName = olapTable.getIndexNameById(mvMeta.getIndexId()); + rows.add(Lists.newArrayList(showStmt.getTable(), + ShowMaterializedViewStatus.buildCreateMVSql(olapTable, + mvName, mvMeta), "utf8", "utf8_general_ci")); + } else { + rows.add(Lists.newArrayList(showStmt.getTable(), mvMeta.getOriginStmt(), + "utf8", "utf8_general_ci")); + } - ShowResultSetMetaData showResultSetMetaData = ShowResultSetMetaData.builder() - .addColumn(new Column("Materialized View", ScalarType.createVarchar(20))) - .addColumn(new Column("Create Materialized View", ScalarType.createVarchar(30))) - .build(); - return new ShowResultSet(showResultSetMetaData, rows); + ShowResultSetMetaData showResultSetMetaData = ShowResultSetMetaData.builder() + .addColumn(new Column("Materialized View", ScalarType.createVarchar(20))) + .addColumn(new Column("Create Materialized View", + ScalarType.createVarchar(30))) + .build(); + return new ShowResultSet(showResultSetMetaData, rows); + } } } } + } finally { + locker.unLockDatabase(db.getId(), LockType.READ); } ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } From c58189cb24008c915aa313b6eef38d961316c36d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 03:25:59 +0000 Subject: [PATCH 4/5] refactor: clarify db fallback locker name Agent-Logs-Url: https://github.com/StarRocks/starrocks/sessions/d259b835-cf31-40c2-b812-8e47115ec482 Co-authored-by: kevincai <771299+kevincai@users.noreply.github.com> --- fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index 1f3d7ea36df125..2f1c4647c336d9 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -749,8 +749,8 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) { ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } else { - Locker locker = new Locker(); - locker.lockDatabase(db.getId(), LockType.READ); + Locker dbLocker = new Locker(); + dbLocker.lockDatabase(db.getId(), LockType.READ); try { // For Sync Materialized View, it is a mv index inside OLAP table, // so we can not get it from database. @@ -782,7 +782,7 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm } } } finally { - locker.unLockDatabase(db.getId(), LockType.READ); + dbLocker.unLockDatabase(db.getId(), LockType.READ); } ErrorReport.reportSemanticException(ErrorCode.ERR_BAD_TABLE_ERROR, showStmt.getTable()); } From 057575eafbfc8f8bf5519ef2059578ca8b7fc2d4 Mon Sep 17 00:00:00 2001 From: Kevin Cai Date: Wed, 13 May 2026 12:33:20 +0800 Subject: [PATCH 5/5] fix conflict Signed-off-by: Kevin Cai --- fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index 2f1c4647c336d9..e902912fdad1c2 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -743,7 +743,7 @@ private ShowResultSet showCreateInternalCatalogTable(ShowCreateTableStmt showStm Database db = GlobalStateMgr.getCurrentState().getLocalMetastore().getDb(showStmt.getDb()); MetaUtils.checkDbNullAndReport(db, showStmt.getDb()); List> rows = Lists.newArrayList(); - TableName tableName = new TableName(showStmt.getCatalogName(), showStmt.getDb(), showStmt.getTable()); + TableName tableName = showStmt.getTbl(); Table table = MetaUtils.getSessionAwareTable(connectContext, db, tableName); if (table == null) { if (showStmt.getType() != ShowCreateTableStmt.CreateTableType.MATERIALIZED_VIEW) {