From dda2469249c2fb49c47c4149bb8579b8e19157d7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 25 Dec 2024 11:41:17 +0800 Subject: [PATCH] branch-3.0: [opt](show) let all types table support show index #45861 (#45895) Cherry-picked from #45861 Co-authored-by: morrySnow --- .../org/apache/doris/qe/ShowExecutor.java | 23 +++++----- .../nereids_syntax_p0/test_show_keys.groovy | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 regression-test/suites/nereids_syntax_p0/test_show_keys.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java index 3dcb7069abf423..381ab1a4aa36dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java @@ -1257,17 +1257,20 @@ private void handleShowIndex() throws AnalysisException { .getCatalogOrAnalysisException(showStmt.getTableName().getCtl()) .getDbOrAnalysisException(showStmt.getDbName()); if (db instanceof Database) { - OlapTable table = db.getOlapTableOrAnalysisException(showStmt.getTableName().getTbl()); - table.readLock(); - try { - List indexes = table.getIndexes(); - for (Index index : indexes) { - rows.add(Lists.newArrayList(showStmt.getTableName().toString(), "", index.getIndexName(), - "", String.join(",", index.getColumns()), "", "", "", "", - "", index.getIndexType().name(), index.getComment(), index.getPropertiesString())); + TableIf table = db.getTableOrAnalysisException(showStmt.getTableName().getTbl()); + if (table instanceof OlapTable) { + OlapTable olapTable = (OlapTable) table; + olapTable.readLock(); + try { + List indexes = olapTable.getIndexes(); + for (Index index : indexes) { + rows.add(Lists.newArrayList(showStmt.getTableName().toString(), "", index.getIndexName(), + "", String.join(",", index.getColumns()), "", "", "", "", + "", index.getIndexType().name(), index.getComment(), index.getPropertiesString())); + } + } finally { + olapTable.readUnlock(); } - } finally { - table.readUnlock(); } } resultSet = new ShowResultSet(showStmt.getMetaData(), rows); diff --git a/regression-test/suites/nereids_syntax_p0/test_show_keys.groovy b/regression-test/suites/nereids_syntax_p0/test_show_keys.groovy new file mode 100644 index 00000000000000..e89a627e2ee1ed --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/test_show_keys.groovy @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_show_keys") { + sql """ + DROP TABLE IF EXISTS test_show_keys + """ + + sql """ + DROP TABLE IF EXISTS test_show_keys_v + """ + + sql """ + CREATE TABLE IF NOT EXISTS test_show_keys ( + c1 int + ) DISTRIBUTED BY HASH(c1) PROPERTIES('replication_num'='1') + """ + + sql """ + CREATE VIEW IF NOT EXISTS test_show_keys_v AS SELECT * FROM test_show_keys + """ + + sql """ + SHOW KEYS FROM test_show_keys + """ + + sql """ + SHOW KEYS FROM test_show_keys_v + """ +}