Skip to content

Commit

Permalink
branch-3.0: [opt](show) let all types table support show index #45861 (
Browse files Browse the repository at this point in the history
…#45895)

Cherry-picked from #45861

Co-authored-by: morrySnow <[email protected]>
  • Loading branch information
github-actions[bot] and morrySnow authored Dec 25, 2024
1 parent d52c555 commit dda2469
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
23 changes: 13 additions & 10 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Index> 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<Index> 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);
Expand Down
44 changes: 44 additions & 0 deletions regression-test/suites/nereids_syntax_p0/test_show_keys.groovy
Original file line number Diff line number Diff line change
@@ -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
"""
}

0 comments on commit dda2469

Please sign in to comment.