Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: partitions #965

Merged
merged 3 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/nightly/en/reference/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
17 changes: 17 additions & 0 deletions docs/nightly/en/reference/sql/information-schema/partitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion docs/nightly/en/user-guide/operations/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/zh/reference/sql/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)。
Expand Down
17 changes: 17 additions & 0 deletions docs/nightly/zh/reference/sql/information-schema/partitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
```

killme2008 marked this conversation as resolved.
Show resolved Hide resolved
示例输出如下:

```sql
*************************** 1. row ***************************
table_catalog: greptime
Expand Down
19 changes: 18 additions & 1 deletion docs/nightly/zh/user-guide/operations/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)。

Expand Down