From c38a6775f426425c1f6b74afffdf06a9d30d2347 Mon Sep 17 00:00:00 2001 From: Felix Li Date: Tue, 19 Nov 2024 18:02:34 -0800 Subject: [PATCH] [BugFix] Fix show keys from support external catalog (#52977) Signed-off-by: Astralidea --- .../src/main/java/com/starrocks/qe/ShowExecutor.java | 6 +++++- .../src/test/java/com/starrocks/qe/ShowExecutorTest.java | 9 +++++++++ 2 files changed, 14 insertions(+), 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 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() {