Skip to content

feat: add Show Regions and update REGION_PEERS docs #1616

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

Merged
merged 4 commits into from
Apr 2, 2025
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
26 changes: 16 additions & 10 deletions docs/reference/sql/information-schema/region-peers.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ DESC REGION_PEERS;
The output is as follows:

```sql
+--------------+--------+------+------+---------+---------------+
| 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 |
+--------------+--------+------+------+---------+---------------+
+---------------+--------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------------+--------+------+------+---------+---------------+
| table_catalog | String | | NO | | FIELD |
| table_schema | String | | NO | | FIELD |
| table_name | String | | NO | | FIELD |
| 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 |
+---------------+--------+------+------+---------+---------------+
6 rows in set (0.00 sec)
```

Fields in the `REGION_PEERS` table are described as follows:

- `table_catalog`: The catalog of the table.
- `table_schema`: The schema of the table.
- `table_name`: The name of the table.
- `region_id`: The ID of the Region.
- `peer_id`: The ID of the Region peer.
- `peer_addr`: The address of the peer.
Expand Down
20 changes: 20 additions & 0 deletions docs/reference/sql/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,26 @@ SHOW COLUMNS FROM monitor WHERE Field = 'cpu';
+-------+--------+------+------+---------+-------+---------------+
```

To list all regions in a table:
```sql
SHOW REGION FROM monitor;
```

```sql
+----------------+---------------+------+--------+
| Table | Region | Peer | Leader |
+----------------+---------------+------+--------+
| monitor | 4398046511104 | 0 | Yes |
+----------------+---------------+------+--------+
```

It is the extension of `INFORMATION_SCHEMA.REGION_PEERS` and supports `WHERE` too.

The syntax is
```sql
SHOW REGION FROM [table] [IN database] [WHERE where]
```

Other `SHOW` statements:
* `SHOW STATUS` and `SHOW VARIABLES` are not supported, just return empty results.
* `SHOW TABLE STATUS` is the extension of `INFORMATION_SCHEMA.TABLES`.
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,26 @@ DESC REGION_PEERS;

```sql
+--------------+--------+------+------+---------+---------------+
| 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 |
+--------------+--------+------+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------------+--------+------+------+---------+---------------+
| table_catalog | String | | NO | | FIELD |
| table_schema | String | | NO | | FIELD |
| table_name | String | | NO | | FIELD |
| 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 |
+---------------+--------+------+------+---------+---------------+
6 rows in set (0.00 sec)
```

`REGION_PEERS` 表中的字段描述如下:

- `table_catalog`:表所属的目录。
- `table_schema`:表所属的数据库。
- `table_name`:表的名称。
- `region_id`:Region 的 ID。
- `peer_id`:Region peer 的 ID。
- `peer_addr`:peer 的地址。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,27 @@ SHOW COLUMNS FROM monitor WHERE Field = 'cpu';
+-------+--------+------+------+---------+-------+---------------+
```

列出表中的所有 Region:

```sql
SHOW REGION FROM monitor;
```

```sql
+----------------+---------------+------+--------+
| Table | Region | Peer | Leader |
+----------------+---------------+------+--------+
| monitor | 4398046511104 | 0 | Yes |
+----------------+---------------+------+--------+
```

这是 `INFORMATION_SCHEMA.REGION_PEERS` 的扩展,并且支持 `WHERE` 子句。

语法是:
```sql
SHOW REGION FROM [table] [IN database] [WHERE where]
```

其他 `SHOW` 扩展语句:
* `SHOW STATUS` 和 `SHOW VARIABLES` 不支持,仅返回空结果。
* `SHOW TABLE STATUS` 是 `INFORMATION_SCHEMA.TABLES` 的扩展。