morningman commented on a change in pull request #5807:
URL: https://github.com/apache/incubator-doris/pull/5807#discussion_r637662968
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,81 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId : dbIds) {
+ Database database = catalog.getDb(dbId);
+ if (database == null) {
+ continue;
+ }
+ database.readLock();
+ Table table = database.getTable(tableId);
+ if (table != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(table.getName());
+ row.add(String.valueOf(database.getId()));
+ rows.add(row);
+ break;
+ }
+ database.readUnlock();
Review comment:
There is no need to lock the database.
And btw, if it is necessary, you should use `try...finally` to do this.
##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -449,6 +458,81 @@ private void handleShowMigrations() throws
AnalysisException {
resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
}
+ private void handleShowDbId() throws AnalysisException {
+ ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+ long dbId = showStmt.getDbId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ Database database = catalog.getDb(dbId);
+ if (database != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ rows.add(row);
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowTableId() throws AnalysisException {
+ ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+ long tableId = showStmt.getTableId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId : dbIds) {
+ Database database = catalog.getDb(dbId);
+ if (database == null) {
+ continue;
+ }
+ database.readLock();
+ Table table = database.getTable(tableId);
+ if (table != null) {
+ List<String> row = new ArrayList<>();
+ row.add(database.getFullName());
+ row.add(table.getName());
+ row.add(String.valueOf(database.getId()));
+ rows.add(row);
+ break;
+ }
+ database.readUnlock();
+ }
+ resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+ }
+
+ private void handleShowPartitionId() throws AnalysisException {
+ ShowPartitionIdStmt showStmt = (ShowPartitionIdStmt) stmt;
+ long partitionId = showStmt.getPartitionId();
+ List<List<String>> rows = Lists.newArrayList();
+ Catalog catalog = ctx.getCatalog();
+ List<Long> dbIds = catalog.getDbIds();
+ for (long dbId : dbIds) {
+ Database database = catalog.getDb(dbId);
+ if (database == null) {
+ continue;
+ }
+ database.readLock();
Review comment:
No need database lock
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]