feat: impl partitions and region_peers information schema (#3278)

* feat: impl partitions table

* fix: typo

* feat: impl region_peers information schema

* chore: rename region_peers to greptime_region_peers

* chore: rename statuses to upper case

* fix: comments

* chore: update partition result

* chore: remove redundant checking

* refactor: replace 42 with constant

* feat: fetch region routes in batch
This commit is contained in:
dennis zhuang
2024-02-19 14:47:14 +08:00
committed by GitHub
parent 1851c20c13
commit 8b73067815
27 changed files with 1004 additions and 90 deletions

View File

@@ -0,0 +1,40 @@
CREATE TABLE my_table (
a INT PRIMARY KEY,
b STRING,
ts TIMESTAMP TIME INDEX,
)
PARTITION BY RANGE COLUMNS (a) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (MAXVALUE),
);
Affected Rows: 0
-- SQLNESS REPLACE (\d{13}) ID
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id |
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
| greptime | public | my_table | p0 | (a) VALUES LESS THAN (10) | ID |
| greptime | public | my_table | p1 | (a) VALUES LESS THAN (20) | ID |
| greptime | public | my_table | p2 | (a) VALUES LESS THAN (MAXVALUE) | ID |
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
-- SQLNESS REPLACE (\d{13}) REGION_ID
-- SQLNESS REPLACE (\d{1}) PEER_ID
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
+---------------+---------+-----------+--------+
| region_id | peer_id | is_leader | status |
+---------------+---------+-----------+--------+
| REGION_ID | PEER_ID | Yes | ALIVE |
| REGION_ID | PEER_ID | Yes | ALIVE |
| REGION_ID | PEER_ID | Yes | ALIVE |
+---------------+---------+-----------+--------+
DROP TABLE my_table;
Affected Rows: 0

View File

@@ -0,0 +1,19 @@
CREATE TABLE my_table (
a INT PRIMARY KEY,
b STRING,
ts TIMESTAMP TIME INDEX,
)
PARTITION BY RANGE COLUMNS (a) (
PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (MAXVALUE),
);
-- SQLNESS REPLACE (\d{13}) ID
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
-- SQLNESS REPLACE (\d{13}) REGION_ID
-- SQLNESS REPLACE (\d{1}) PEER_ID
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
DROP TABLE my_table;

View File

@@ -34,6 +34,7 @@ show tables;
| key_column_usage |
| optimizer_trace |
| parameters |
| partitions |
| profiling |
| referential_constraints |
| routines |

View File

@@ -26,6 +26,7 @@ order by table_schema, table_name;
| greptime | information_schema | key_column_usage | LOCAL TEMPORARY | 16 | |
| greptime | information_schema | optimizer_trace | LOCAL TEMPORARY | 17 | |
| greptime | information_schema | parameters | LOCAL TEMPORARY | 18 | |
| greptime | information_schema | partitions | LOCAL TEMPORARY | 28 | |
| greptime | information_schema | profiling | LOCAL TEMPORARY | 19 | |
| greptime | information_schema | referential_constraints | LOCAL TEMPORARY | 20 | |
| greptime | information_schema | routines | LOCAL TEMPORARY | 21 | |
@@ -182,6 +183,32 @@ select * from information_schema.columns order by table_schema, table_name, colu
| greptime | information_schema | parameters | specific_catalog | String | FIELD | | No | String | |
| greptime | information_schema | parameters | specific_name | String | FIELD | | No | String | |
| greptime | information_schema | parameters | specific_schema | String | FIELD | | No | String | |
| greptime | information_schema | partitions | avg_row_length | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | check_time | DateTime | FIELD | | Yes | DateTime | |
| greptime | information_schema | partitions | checksum | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | create_time | DateTime | FIELD | | Yes | DateTime | |
| greptime | information_schema | partitions | data_free | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | data_length | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | greptime_partition_id | UInt64 | FIELD | | Yes | UInt64 | |
| greptime | information_schema | partitions | index_length | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | max_data_length | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | nodegroup | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | partition_comment | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | partition_description | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | partition_expression | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | partition_method | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | partition_name | String | FIELD | | No | String | |
| greptime | information_schema | partitions | partition_ordinal_position | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | subpartition_expression | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | subpartition_method | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | subpartition_name | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | subpartition_ordinal_position | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | table_catalog | String | FIELD | | No | String | |
| greptime | information_schema | partitions | table_name | String | FIELD | | No | String | |
| greptime | information_schema | partitions | table_rows | Int64 | FIELD | | Yes | Int64 | |
| greptime | information_schema | partitions | table_schema | String | FIELD | | No | String | |
| greptime | information_schema | partitions | tablespace_name | String | FIELD | | Yes | String | |
| greptime | information_schema | partitions | update_time | DateTime | FIELD | | Yes | DateTime | |
| greptime | information_schema | profiling | block_ops_in | Int64 | FIELD | | No | Int64 | |
| greptime | information_schema | profiling | block_ops_out | Int64 | FIELD | | No | Int64 | |
| greptime | information_schema | profiling | context_involuntary | Int64 | FIELD | | No | Int64 | |
@@ -528,7 +555,7 @@ select * from key_column_usage;
+--------------------+-------------------+-----------------+---------------+--------------+------------+-------------+------------------+-------------------------------+-------------------------+-----------------------+------------------------+
-- tables not implemented
desc table COLUMN_PRIVILEGES;
DESC TABLE COLUMN_PRIVILEGES;
+----------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
@@ -542,14 +569,14 @@ desc table COLUMN_PRIVILEGES;
| is_grantable | String | | NO | | FIELD |
+----------------+--------+-----+------+---------+---------------+
select * from COLUMN_PRIVILEGES;
SELECT * FROM COLUMN_PRIVILEGES;
+---------+---------------+--------------+------------+-------------+----------------+--------------+
| grantee | table_catalog | table_schema | table_name | column_name | privilege_type | is_grantable |
+---------+---------------+--------------+------------+-------------+----------------+--------------+
+---------+---------------+--------------+------------+-------------+----------------+--------------+
desc table COLUMN_STATISTICS;
DESC TABLE COLUMN_STATISTICS;
+-------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
@@ -560,14 +587,14 @@ desc table COLUMN_STATISTICS;
| histogram | String | | NO | | FIELD |
+-------------+--------+-----+------+---------+---------------+
select * from COLUMN_STATISTICS;
SELECT * FROM COLUMN_STATISTICS;
+-------------+------------+-------------+-----------+
| schema_name | table_name | column_name | histogram |
+-------------+------------+-------------+-----------+
+-------------+------------+-------------+-----------+
select * from CHARACTER_SETS;
SELECT * FROM CHARACTER_SETS;
+--------------------+----------------------+---------------+--------+
| character_set_name | default_collate_name | description | maxlen |
@@ -575,7 +602,7 @@ select * from CHARACTER_SETS;
| utf8 | utf8_bin | UTF-8 Unicode | 4 |
+--------------------+----------------------+---------------+--------+
select * from COLLATIONS;
SELECT * FROM COLLATIONS;
+----------------+--------------------+----+------------+-------------+---------+
| collation_name | character_set_name | id | is_default | is_compiled | sortlen |
@@ -583,7 +610,7 @@ select * from COLLATIONS;
| utf8_bin | utf8 | 1 | Yes | Yes | 1 |
+----------------+--------------------+----+------------+-------------+---------+
select * from COLLATION_CHARACTER_SET_APPLICABILITY;
SELECT * FROM COLLATION_CHARACTER_SET_APPLICABILITY;
+----------------+--------------------+
| collation_name | character_set_name |
@@ -591,7 +618,7 @@ select * from COLLATION_CHARACTER_SET_APPLICABILITY;
| utf8_bin | utf8 |
+----------------+--------------------+
desc table CHECK_CONSTRAINTS;
DESC TABLE CHECK_CONSTRAINTS;
+--------------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
@@ -602,14 +629,14 @@ desc table CHECK_CONSTRAINTS;
| check_clause | String | | NO | | FIELD |
+--------------------+--------+-----+------+---------+---------------+
select * from CHECK_CONSTRAINTS;
SELECT * FROM CHECK_CONSTRAINTS;
+--------------------+-------------------+-----------------+--------------+
| constraint_catalog | constraint_schema | constraint_name | check_clause |
+--------------------+-------------------+-----------------+--------------+
+--------------------+-------------------+-----------------+--------------+
desc table RUNTIME_METRICS;
DESC TABLE RUNTIME_METRICS;
+-------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
@@ -622,6 +649,19 @@ desc table RUNTIME_METRICS;
| timestamp | TimestampMillisecond | | NO | | FIELD |
+-------------+----------------------+-----+------+---------+---------------+
DESC TABLE GREPTIME_REGION_PEERS;
+--------------+--------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+--------------+--------+-----+------+---------+---------------+
| region_id | UInt64 | | NO | | FIELD |
| peer_id | UInt64 | | YES | | FIELD |
| peer_addr | String | | YES | | FIELD |
| is_leader | String | | YES | | FIELD |
| status | String | | YES | | FIELD |
| down_seconds | Int64 | | YES | | FIELD |
+--------------+--------+-----+------+---------+---------------+
drop table my_db.foo;
Affected Rows: 0

View File

@@ -97,25 +97,27 @@ desc table key_column_usage;
select * from key_column_usage;
-- tables not implemented
desc table COLUMN_PRIVILEGES;
DESC TABLE COLUMN_PRIVILEGES;
select * from COLUMN_PRIVILEGES;
SELECT * FROM COLUMN_PRIVILEGES;
desc table COLUMN_STATISTICS;
DESC TABLE COLUMN_STATISTICS;
select * from COLUMN_STATISTICS;
SELECT * FROM COLUMN_STATISTICS;
select * from CHARACTER_SETS;
SELECT * FROM CHARACTER_SETS;
select * from COLLATIONS;
SELECT * FROM COLLATIONS;
select * from COLLATION_CHARACTER_SET_APPLICABILITY;
SELECT * FROM COLLATION_CHARACTER_SET_APPLICABILITY;
desc table CHECK_CONSTRAINTS;
DESC TABLE CHECK_CONSTRAINTS;
select * from CHECK_CONSTRAINTS;
SELECT * FROM CHECK_CONSTRAINTS;
desc table RUNTIME_METRICS;
DESC TABLE RUNTIME_METRICS;
DESC TABLE GREPTIME_REGION_PEERS;
drop table my_db.foo;