From a7d3ffda898ed0300e6551d0de89623520087586 Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Sun, 19 May 2024 12:22:16 +0800 Subject: [PATCH] fix: partitions (#965) Co-authored-by: tison --- 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 | 17 +++++++++++++++++ .../nightly/zh/user-guide/operations/admin.md | 19 ++++++++++++++++++- 6 files changed, 72 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..207562679 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). +* `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. +* `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. + +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..b3f008ccb 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)的表的名称。 +* `partition_name`:分区(region)的名称。 +* `partition_ordinal_position`:所有分区按照定义的顺序进行索引,1 是分配给第一个分区的编号。 +* `partition_method`:该值始终为 `RANGE`,GreptimeDB 仅支持范围分区。 +* `partition_expression`:该分区的表达式。 +* `create_time`:分区创建的时间。 +* `greptime_partition_id`:GreptimeDB 扩展字段,也就是 Region Id。 + +创建一张分区表并查询: + ```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 ); + +--- 查询表的分区信息--- SELECT * FROM PARTITIONS WHERE table_schema='public' AND table_name='test_p'\G ``` +示例输出如下: + ```sql *************************** 1. row *************************** table_catalog: greptime 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)。