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 ae20b132227c2..f9044fac0057b 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 @@ -2177,7 +2177,11 @@ public ShowResultSet visitShowDynamicPartitionStatement(ShowDynamicPartitionStmt @Override public ShowResultSet visitShowIndexStatement(ShowIndexStmt statement, ConnectContext context) { List> rows = Lists.newArrayList(); - Database db = context.getGlobalStateMgr().getLocalMetastore().getDb(statement.getDbName()); + String catalogName = statement.getTableName().getCatalog(); + if (catalogName == null) { + catalogName = context.getCurrentCatalog(); + } + Database db = GlobalStateMgr.getCurrentState().getMetadataMgr().getDb(catalogName, statement.getDbName()); MetaUtils.checkDbNullAndReport(db, statement.getDbName()); Table table = MetaUtils.getSessionAwareTable(context, db, statement.getTableName()); if (table == null) { diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java index 32ada85042afe..d073fdf9b1180 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java @@ -105,6 +105,7 @@ import com.starrocks.sql.ast.ShowDbStmt; import com.starrocks.sql.ast.ShowEnginesStmt; import com.starrocks.sql.ast.ShowGrantsStmt; +import com.starrocks.sql.ast.ShowIndexStmt; import com.starrocks.sql.ast.ShowMaterializedViewsStmt; import com.starrocks.sql.ast.ShowPartitionsStmt; import com.starrocks.sql.ast.ShowProcedureStmt; @@ -1173,6 +1174,14 @@ public Table getTable(String catalogName, String dbName, String tblName) { resultSet.getResultRows().get(0).get(1)); } + @Test + public void testShowKeysFromTable() { + ShowIndexStmt stmt = new ShowIndexStmt("test_db", + new TableName(null, "test_db", "test_table")); + ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx); + Assert.assertEquals(0, resultSet.getResultRows().size()); + } + @Test public void testShowCreateExternalCatalog() throws AnalysisException, DdlException { new MockUp() {