From 597d06d89bfb795332c88ff279664cfc1b7a3f85 Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Sat, 18 May 2024 19:36:23 +0800 Subject: [PATCH 1/3] fix: partitions --- docs/nightly/en/reference/sql/functions.md | 2 +- .../sql/information-schema/partitions.md | 17 +++++++++++++++++ .../nightly/en/user-guide/operations/admin.md | 19 ++++++++++++++++++- docs/nightly/zh/reference/sql/functions.md | 2 +- .../sql/information-schema/partitions.md | 15 +++++++++++++++ .../nightly/zh/user-guide/operations/admin.md | 19 ++++++++++++++++++- 6 files changed, 70 insertions(+), 4 deletions(-) diff --git a/docs/nightly/en/reference/sql/functions.md b/docs/nightly/en/reference/sql/functions.md index 88500ba8f..beeadd279 100644 --- a/docs/nightly/en/reference/sql/functions.md +++ b/docs/nightly/en/reference/sql/functions.md @@ -42,7 +42,7 @@ Please refer to [API documentation](https://greptimedb.rs/script/python/rspython GreptimeDB provides some administration functions to manage the database and data: * `flush_table(table_name)` to flush a table's memtables into SST file by table name. -* `flush_region(region_id)` to flush a region's memtables into SST file by region id. Find the region id through [REGION_PEERS](./information-schema/region-peers.md) table. +* `flush_region(region_id)` to flush a region's memtables into SST file by region id. Find the region id through [PARTITIONS](./information-schema/partitions.md) table. * `compact_table(table_name)` to schedule a compaction task for a table by table name. * `compact_region(region_id)` to schedule a compaction task for a region by region id. * `migrate_region(region_id, from_peer, to_peer, [timeout])` to migrate regions between datanodes, please read the [Region Migration](/user-guide/operations/region-migration). diff --git a/docs/nightly/en/reference/sql/information-schema/partitions.md b/docs/nightly/en/reference/sql/information-schema/partitions.md index 7310a689f..aa8b60dcf 100644 --- a/docs/nightly/en/reference/sql/information-schema/partitions.md +++ b/docs/nightly/en/reference/sql/information-schema/partitions.md @@ -43,6 +43,19 @@ The output is as follows: 26 rows in set (0.01 sec) ``` +Main columns: +* `table_catalog`: The name of the catalog to which the table belongs. This value is always `def`. +* `table_schema`: The name of the schema (database) to which the table belongs. +* `table_name`: The name of the table containing the partition(region). +* `parition_name`: The name of the partition(region). +* `partition_ordinal_position`: All partitions are indexed in the same order as they are defined, with 1 being the number assigned to the first partition. +* `parition_method`: This value is always `RANGE`, GreptimeDB only supports range partitioning. +* `partition_expression`: The expression of this partition. +* `create_time`: The time that the partition was created. +* `greptime_partition_id`: GreptimeDB extended field, it's the Region Id. + +For example, create a partitioned table: + ```sql CREATE TABLE public.test_p ( a INT PRIMARY KEY, @@ -54,9 +67,13 @@ PARTITION ON COLUMNS (a) ( a > 10 AND a < 20, a >= 20 ); + +--- Query the partitions of the table -- SELECT * FROM PARTITIONS WHERE table_schema='public' AND table_name='test_p'\G ``` +Outputs: + ```sql *************************** 1. row *************************** table_catalog: greptime diff --git a/docs/nightly/en/user-guide/operations/admin.md b/docs/nightly/en/user-guide/operations/admin.md index f19775674..354987199 100644 --- a/docs/nightly/en/user-guide/operations/admin.md +++ b/docs/nightly/en/user-guide/operations/admin.md @@ -12,7 +12,24 @@ This document addresses strategies and practices used in the operation of Grepti ### Runtime information * Find the topology information of the cluster though [CLUSTER_INFO](/reference/sql/information-schema/cluster-info.md) table. -* Find the table regions distribution though [REGION_PEERS](/reference/sql/information-schema/region-peers.md) table. +* Find the table regions distribution though [PARTITIONS](/reference/sql/information-schema/partitions.md) and [REGION_PEERS](/reference/sql/information-schema/region-peers.md) tables. + +For example, find all the region id of a table: + +```sql +SELECT greptime_partition_id FROM PARTITIONS WHERE table_name = 'monitor' +``` + +Find the distribution of all regions in a table: + +```sql +SELECT b.peer_id as datanode_id, + a.greptime_partition_id as region_id +FROM information_schema.partitions a LEFT JOIN information_schema.region_peers b +ON a.greptime_partition_id = b.region_id +WHERE a.table_name='monitor' +ORDER BY datanode_id ASC +``` The `INFORMATION_SCHEMA` database provides access to system metadata, such as the name of a database or table, the data type of a column, etc. Please read the [reference](/reference/sql/information-schema/overview.md). diff --git a/docs/nightly/zh/reference/sql/functions.md b/docs/nightly/zh/reference/sql/functions.md index f00dc54a4..62987f7aa 100644 --- a/docs/nightly/zh/reference/sql/functions.md +++ b/docs/nightly/zh/reference/sql/functions.md @@ -41,7 +41,7 @@ arrow_cast(expression, datatype) GreptimeDB 提供了一些管理函数来管理数据库和数据: * `flush_table(table_name)` 通过表名将表的内存表刷写到 SST 文件。 -* `flush_region(region_id)` 通过 Region Id 将 Region 的内存表刷写到 SST 文件。可以通过 [REGION_PEERS](./information-schema/region-peers.md) 表查找 Region Id。 +* `flush_region(region_id)` 通过 Region Id 将 Region 的内存表刷写到 SST 文件。可以通过 [PARTITIONS](./information-schema/partitions.md) 表查找一张表的所有 Region Id。 * `compact_table(table_name)` 通过表名为表发起compaction 任务。 * `compact_region(region_id)` 通过 Region Id 为 Region 发起 compaction 任务。 * `migrate_region(region_id, from_peer, to_peer, [timeout])` 在 Datanode 之间迁移 Region,请阅读 [ Region迁移](/user-guide/operations/region-migration)。 diff --git a/docs/nightly/zh/reference/sql/information-schema/partitions.md b/docs/nightly/zh/reference/sql/information-schema/partitions.md index 860bb893d..c17823c49 100644 --- a/docs/nightly/zh/reference/sql/information-schema/partitions.md +++ b/docs/nightly/zh/reference/sql/information-schema/partitions.md @@ -43,6 +43,19 @@ DESC PARTITIONS; 26 rows in set (0.01 sec) ``` +主要列包括: +* `table_catalog`:表所属目录的名称。该值始终为 `def`。 +* `table_schema`:表所属的 schema(数据库)的名称。 +* `table_name`:包含分区(region)的表的名称。 +* `parition_name`:分区(region)的名称。 +* `partition_ordinal_position`:所有分区按照定义的顺序进行索引,1 是分配给第一个分区的编号。 +* `parition_method`:该值始终为 `RANGE`,GreptimeDB 仅支持范围分区。 +* `partition_expression`:该分区的表达式。 +* `create_time`:分区创建的时间。 +* `greptime_partition_id`:GreptimeDB 扩展字段,也就是 Region Id。 + +创建一张分区表并查询: + ```sql CREATE TABLE public.test_p ( a INT PRIMARY KEY, @@ -54,6 +67,8 @@ PARTITION ON COLUMNS (a) ( a > 10 AND a < 20, a >= 20 ); + +--- 查询表的分区信息--- SELECT * FROM PARTITIONS WHERE table_schema='public' AND table_name='test_p'\G ``` diff --git a/docs/nightly/zh/user-guide/operations/admin.md b/docs/nightly/zh/user-guide/operations/admin.md index aefe73c5e..d568762ab 100644 --- a/docs/nightly/zh/user-guide/operations/admin.md +++ b/docs/nightly/zh/user-guide/operations/admin.md @@ -12,7 +12,24 @@ ### 运行时信息 * 通过 [CLUSTER_INFO](/reference/sql/information-schema/cluster-info.md) 表查找集群的拓扑信息。 -* 通过 [REGION_PEERS](/reference/sql/information-schema/region-peers.md) 表查找表的 Region 分布。 +* 通过 [PARTITIONS](reference/sql/information-schema/partitions.md) 表和[REGION_PEERS](/reference/sql/information-schema/region-peers.md) 表查找表的 Region 分布。 + +例如查询一张表的所有 Region Id: + +```sql +SELECT greptime_partition_id FROM PARTITIONS WHERE table_name = 'monitor' +``` + +查询一张表的 region 分布在哪些 datanode 上: + +```sql +SELECT b.peer_id as datanode_id, + a.greptime_partition_id as region_id +FROM information_schema.partitions a LEFT JOIN information_schema.region_peers b +ON a.greptime_partition_id = b.region_id +WHERE a.table_name='monitor' +ORDER BY datanode_id ASC +``` `INFORMATION_SCHEMA` 数据库提供了对系统元数据的访问,如数据库或表的名称、列的数据类型等。请阅读 [参考文档](/reference/sql/information-schema/overview.md)。 From 722b9a85b981a11a4a5ee9c23ba16b32d0de9650 Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Sat, 18 May 2024 19:41:35 +0800 Subject: [PATCH 2/3] fix: typo --- .../nightly/en/reference/sql/information-schema/partitions.md | 4 ++-- .../nightly/zh/reference/sql/information-schema/partitions.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/nightly/en/reference/sql/information-schema/partitions.md b/docs/nightly/en/reference/sql/information-schema/partitions.md index aa8b60dcf..207562679 100644 --- a/docs/nightly/en/reference/sql/information-schema/partitions.md +++ b/docs/nightly/en/reference/sql/information-schema/partitions.md @@ -47,9 +47,9 @@ Main columns: * `table_catalog`: The name of the catalog to which the table belongs. This value is always `def`. * `table_schema`: The name of the schema (database) to which the table belongs. * `table_name`: The name of the table containing the partition(region). -* `parition_name`: The name of the partition(region). +* `partition_name`: The name of the partition(region). * `partition_ordinal_position`: All partitions are indexed in the same order as they are defined, with 1 being the number assigned to the first partition. -* `parition_method`: This value is always `RANGE`, GreptimeDB only supports range partitioning. +* `partition_method`: This value is always `RANGE`, GreptimeDB only supports range partitioning. * `partition_expression`: The expression of this partition. * `create_time`: The time that the partition was created. * `greptime_partition_id`: GreptimeDB extended field, it's the Region Id. diff --git a/docs/nightly/zh/reference/sql/information-schema/partitions.md b/docs/nightly/zh/reference/sql/information-schema/partitions.md index c17823c49..8b15cfcd9 100644 --- a/docs/nightly/zh/reference/sql/information-schema/partitions.md +++ b/docs/nightly/zh/reference/sql/information-schema/partitions.md @@ -47,9 +47,9 @@ DESC PARTITIONS; * `table_catalog`:表所属目录的名称。该值始终为 `def`。 * `table_schema`:表所属的 schema(数据库)的名称。 * `table_name`:包含分区(region)的表的名称。 -* `parition_name`:分区(region)的名称。 +* `partition_name`:分区(region)的名称。 * `partition_ordinal_position`:所有分区按照定义的顺序进行索引,1 是分配给第一个分区的编号。 -* `parition_method`:该值始终为 `RANGE`,GreptimeDB 仅支持范围分区。 +* `partition_method`:该值始终为 `RANGE`,GreptimeDB 仅支持范围分区。 * `partition_expression`:该分区的表达式。 * `create_time`:分区创建的时间。 * `greptime_partition_id`:GreptimeDB 扩展字段,也就是 Region Id。 From 112408e6453fb3c833faca2ab794f1d0a9c4e9e5 Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Sat, 18 May 2024 19:51:58 +0800 Subject: [PATCH 3/3] chore: apply suggestion Co-authored-by: tison --- docs/nightly/zh/reference/sql/information-schema/partitions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/nightly/zh/reference/sql/information-schema/partitions.md b/docs/nightly/zh/reference/sql/information-schema/partitions.md index 8b15cfcd9..b3f008ccb 100644 --- a/docs/nightly/zh/reference/sql/information-schema/partitions.md +++ b/docs/nightly/zh/reference/sql/information-schema/partitions.md @@ -72,6 +72,8 @@ PARTITION ON COLUMNS (a) ( SELECT * FROM PARTITIONS WHERE table_schema='public' AND table_name='test_p'\G ``` +示例输出如下: + ```sql *************************** 1. row *************************** table_catalog: greptime