add information_schema.metadata_name_idsfor quickly get catlogs,db,table.
1. table struct :
```mysql
mysql> desc internal.information_schema.metadata_name_ids;
+---------------+--------------+------+-------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-------+---------+-------+
| CATALOG_ID | BIGINT | Yes | false | NULL | |
| CATALOG_NAME | VARCHAR(512) | Yes | false | NULL | |
| DATABASE_ID | BIGINT | Yes | false | NULL | |
| DATABASE_NAME | VARCHAR(64) | Yes | false | NULL | |
| TABLE_ID | BIGINT | Yes | false | NULL | |
| TABLE_NAME | VARCHAR(64) | Yes | false | NULL | |
+---------------+--------------+------+-------+---------+-------+
6 rows in set (0.00 sec)
mysql> select * from internal.information_schema.metadata_name_ids where CATALOG_NAME="hive1" limit 1 \G;
*************************** 1. row ***************************
CATALOG_ID: 113008
CATALOG_NAME: hive1
DATABASE_ID: 113042
DATABASE_NAME: ssb1_parquet
TABLE_ID: 114009
TABLE_NAME: dates
1 row in set (0.07 sec)
```
2. when you create / drop catalog , need not refresh catalog .
```mysql
mysql> select count(*) from internal.information_schema.metadata_name_ids\G;
*************************** 1. row ***************************
count(*): 21301
1 row in set (0.34 sec)
mysql> drop catalog hive2;
Query OK, 0 rows affected (0.01 sec)
mysql> select count(*) from internal.information_schema.metadata_name_ids\G;
*************************** 1. row ***************************
count(*): 10665
1 row in set (0.04 sec)
mysql> create catalog hive3 ...
mysql> select count(*) from internal.information_schema.metadata_name_ids\G;
*************************** 1. row ***************************
count(*): 21301
1 row in set (0.32 sec)
```
3. create / drop table , need not refresh catalog .
```mysql
mysql> CREATE TABLE IF NOT EXISTS demo.example_tbl ... ;
mysql> select count(*) from internal.information_schema.metadata_name_ids\G;
*************************** 1. row ***************************
count(*): 10666
1 row in set (0.04 sec)
mysql> drop table demo.example_tbl;
Query OK, 0 rows affected (0.01 sec)
mysql> select count(*) from internal.information_schema.metadata_name_ids\G;
*************************** 1. row ***************************
count(*): 10665
1 row in set (0.04 sec)
```
4. you can set query time , prevent queries from taking too long .
```
fe.conf : query_metadata_name_ids_timeout
the time used to obtain all tables in one database
```
5. add information_schema.profiling in order to Compatible with mysql
```mysql
mysql> select * from information_schema.profiling;
Empty set (0.07 sec)
mysql> set profiling=1;
Query OK, 0 rows affected (0.01 sec)
```
103 lines
3.8 KiB
C++
103 lines
3.8 KiB
C++
// 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.
|
|
|
|
#include "exec/schema_scanner/schema_profiling_scanner.h"
|
|
|
|
#include <gen_cpp/Descriptors_types.h>
|
|
#include <gen_cpp/FrontendService_types.h>
|
|
#include <stdint.h>
|
|
|
|
#include "exec/schema_scanner/schema_helper.h"
|
|
#include "runtime/define_primitive_type.h"
|
|
#include "util/runtime_profile.h"
|
|
#include "vec/common/string_ref.h"
|
|
|
|
namespace doris {
|
|
class RuntimeState;
|
|
namespace vectorized {
|
|
class Block;
|
|
} // namespace vectorized
|
|
|
|
std::vector<SchemaScanner::ColumnDesc> SchemaProfilingScanner::_s_tbls_columns = {
|
|
// name, type, size, is_null
|
|
{"QUERY_ID", TYPE_INT, sizeof(int), false},
|
|
{"SEQ", TYPE_INT, sizeof(int), false},
|
|
{"STATE", TYPE_VARCHAR, sizeof(StringRef), false},
|
|
{"DURATION", TYPE_DOUBLE, sizeof(double), false},
|
|
{"CPU_USER", TYPE_DOUBLE, sizeof(double), true},
|
|
{"CPU_SYSTEM", TYPE_DOUBLE, sizeof(double), true},
|
|
{"CONTEXT_VOLUNTARY", TYPE_INT, sizeof(int), true},
|
|
{"CONTEXT_INVOLUNTARY", TYPE_INT, sizeof(int), true},
|
|
{"BLOCK_OPS_IN", TYPE_INT, sizeof(int), true},
|
|
{"BLOCK_OPS_OUT", TYPE_INT, sizeof(int), true},
|
|
{"MESSAGES_SENT", TYPE_INT, sizeof(int), true},
|
|
{"MESSAGES_RECEIVED", TYPE_INT, sizeof(int), true},
|
|
{"PAGE_FAULTS_MAJOR", TYPE_INT, sizeof(int), true},
|
|
{"PAGE_FAULTS_MINOR", TYPE_INT, sizeof(int), true},
|
|
{"SWAPS", TYPE_INT, sizeof(int), true},
|
|
{"SOURCE_FUNCTION", TYPE_VARCHAR, sizeof(StringRef), false},
|
|
{"SOURCE_FILE", TYPE_VARCHAR, sizeof(StringRef), false},
|
|
{"SOURCE_LINE", TYPE_INT, sizeof(int), true},
|
|
};
|
|
|
|
SchemaProfilingScanner::SchemaProfilingScanner()
|
|
: SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_PROFILING) {}
|
|
|
|
SchemaProfilingScanner::~SchemaProfilingScanner() {}
|
|
|
|
Status SchemaProfilingScanner::start(RuntimeState* state) {
|
|
if (!_is_init) {
|
|
return Status::InternalError("used before initialized.");
|
|
}
|
|
SCOPED_TIMER(_get_db_timer);
|
|
TGetDbsParams db_params;
|
|
if (nullptr != _param->db) {
|
|
db_params.__set_pattern(*(_param->db));
|
|
}
|
|
if (nullptr != _param->catalog) {
|
|
db_params.__set_catalog(*(_param->catalog));
|
|
}
|
|
if (nullptr != _param->current_user_ident) {
|
|
db_params.__set_current_user_ident(*(_param->current_user_ident));
|
|
} else {
|
|
if (nullptr != _param->user) {
|
|
db_params.__set_user(*(_param->user));
|
|
}
|
|
if (nullptr != _param->user_ip) {
|
|
db_params.__set_user_ip(*(_param->user_ip));
|
|
}
|
|
}
|
|
|
|
if (nullptr == _param->ip || 0 == _param->port) {
|
|
return Status::InternalError("IP or port doesn't exists");
|
|
}
|
|
return Status::OK();
|
|
}
|
|
|
|
Status SchemaProfilingScanner::get_next_block(vectorized::Block* block, bool* eos) {
|
|
if (!_is_init) {
|
|
return Status::InternalError("Used before initialized.");
|
|
}
|
|
if (nullptr == block || nullptr == eos) {
|
|
return Status::InternalError("input pointer is nullptr.");
|
|
}
|
|
*eos = true;
|
|
return Status::OK();
|
|
}
|
|
|
|
} // namespace doris
|