Skip to content
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 TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
- [`SHOW [GLOBAL|SESSION] VARIABLES`](/sql-statements/sql-statement-show-variables.md)
- [`SHOW WARNINGS`](/sql-statements/sql-statement-show-warnings.md)
- [`SHOW PROFILES`](/sql-statements/sql-statement-show-profiles.md)
- [`SHOW TABLE NEXT_ROW_ID`](/sql-statements/sql-statement-show-table-next-row-id.md)
- [`SHOW TABLE NEXT_ROW_ID`](/sql-statements/sql-statement-show-table-next-rowid.md)
- [`SPLIT REGION`](/sql-statements/sql-statement-split-region.md)
- [`START TRANSACTION`](/sql-statements/sql-statement-start-transaction.md)
- [`TRACE`](/sql-statements/sql-statement-trace.md)
Expand Down
57 changes: 0 additions & 57 deletions sql-statements/sql-statement-show-table-next-row-id.md

This file was deleted.

23 changes: 16 additions & 7 deletions sql-statements/sql-statement-show-table-next-rowid.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
title: SHOW TABLE NEXT_ROW_ID
summary: TiDB 数据库中 SHOW TABLE NEXT_ROW_ID 的使用概况。
category: reference
aliases: ['/docs-cn/dev/reference/sql/statements/show-status/']
---

# SHOW TABLE NEXT_ROW_ID

`SHOW TABLE NEXT_ROW_ID` 语句用于查看 TiDB 中一张表的隐式分配的全局 Row ID 情况
`SHOW TABLE NEXT_ROW_ID` 语句用于显示用表中某些特殊列的详情,主要包含以下几种类型

- 对于大多数表,TiDB 会为每一条记录分配一个表内唯一的数字作为 ID,ID 最大分配值被持久化在存储层,每个 TiDB Server 会按需向持久层申请一段空间缓存在内存中,用于 ID 的分配。该语法用于查询存储层的所记录的下一个分配值。
- 对于主键被定义为整数类型的表,由于 TiDB 进行了优化,将整数主键映射为了 Row ID,因此对于该类型的表,`SHOW TABLE NEXT_ROW_ID` 的值没有意义。
* TiDB 创建的 `AUTO_INCREMENT` 类型列,即 `_tidb_rowid` 列
* 用户创建的 `AUTO_INCREMENT` 类型列
* 用户创建的 [`AUTO_RANDOM`](/auto-random.md) 类型列
* 用户创建的 [`SEQUENCE`](/sql-statements/sql-statement-create-sequence.md) 对象信息

## 语法图

Expand All @@ -24,6 +25,8 @@ aliases: ['/docs-cn/dev/reference/sql/statements/show-status/']

## 示例

对于新建的表,由于没有任何的 Row ID 分配,NEXT_GLOBAL_ROW_ID 值为 1

{{< copyable "sql" >}}

```sql
Expand All @@ -32,7 +35,6 @@ Query OK, 0 rows affected (0.06 sec)
```

```sql
# 对于新建的表,由于没有任何的 Row ID 分配,NEXT_GLOBAL_ROW_ID 值为 1
show table t next_row_id;
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
Expand All @@ -42,6 +44,8 @@ show table t next_row_id;
1 row in set (0.00 sec)
```

表中写入了数据,负责写入的 TiDB Server 一次性向存储层请求了 30000 个 ID 缓存起来,NEXT_GLOBAL_ROW_ID 值为 30001

```sql
insert into t values (), (), ();
Query OK, 3 rows affected (0.02 sec)
Expand All @@ -50,7 +54,6 @@ Records: 3 Duplicates: 0 Warnings: 0

```sql
show table t next_row_id;
# 表中写入了数据,负责写入的 TiDB Server 一次性向存储层请求了 30000 个 ID 缓存起来,NEXT_GLOBAL_ROW_ID 值为 30001
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
+---------+------------+-------------+--------------------+
Expand All @@ -61,4 +64,10 @@ show table t next_row_id;

## MySQL 兼容性

`SHOW TABLE NEXT_ROW_ID` 语句是 TiDB 特有的语法。
`SHOW TABLE NEXT_ROW_ID` 语句是 TiDB 特有的语法。

## 另请参阅

* [CREATE TABLE](/sql-statements/sql-statement-create-table.md)
* [AUTO_RANDOM](/auto-random.md)
* [CREATE_SEQUENCE](/sql-statements/sql-statement-create-sequence.md)