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
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
+ [`SHOW [FULL] PROCESSSLIST`](/sql-statements/sql-statement-show-processlist.md)
+ [`SHOW SCHEMAS`](/sql-statements/sql-statement-show-schemas.md)
+ [`SHOW STATUS`](/sql-statements/sql-statement-show-status.md)
+ [`SHOW TABLE NEXT_ROW_ID`](/sql-statements/sql-statement-show-table-next-rowid.md)
+ [`SHOW TABLE REGIONS`](/sql-statements/sql-statement-show-table-regions.md)
+ [`SHOW TABLE STATUS`](/sql-statements/sql-statement-show-table-status.md)
+ [`SHOW [FULL] TABLES`](/sql-statements/sql-statement-show-tables.md)
Expand Down
4 changes: 2 additions & 2 deletions sql-statements/sql-statement-show-processlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ This statement lists the current sessions connected to the same TiDB server. The

## Synopsis

**ShowStmt:**
**ShowProcesslistStmt:**

![ShowStmt](/media/sqlgram/ShowStmt.png)
![ShowProcesslistStmt](/media/sqlgram/ShowProcesslistStmt.png)

**OptFull:**

Expand Down
63 changes: 63 additions & 0 deletions sql-statements/sql-statement-show-table-next-rowid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
Comment thread
tangenta marked this conversation as resolved.
title: SHOW TABLE NEXT_ROW_ID
summary: Learn the usage of `SHOW TABLE NEXT_ROW_ID` in TiDB.
category: reference
---

# SHOW TABLE NEXT_ROW_ID

`SHOW TABLE NEXT_ROW_ID` can be used to show the implicitly allocated global Row ID of a table.

- For most of the tables, TiDB allocates a unique number for each record. The max allocated ID is persisted in the storage layer. Each TiDB server applies for a range of IDs on demand and caches them for ID allocation. This syntax can be used to query the next value to allocate, recorded in the storage layer.
- For the tables with integer primary key for optimization, TiDB maps the values in the primary key column to Row ID. Thus, `SHOW TABLE NEXT_ROW_ID` is meaningless for these tables.

## Synopsis

**ShowTableNextRowIDStmt:**

![ShowTableNextRowIDStmt](/media/sqlgram/ShowTableNextRowIDStmt.png)

**TableName:**

![TableName](/media/sqlgram/TableName.png)

## Examples

{{< copyable "sql" >}}

```sql
create table t(a int);
Query OK, 0 rows affected (0.06 sec)
```

```sql
# For newly created tables, NEXT_GLOBAL_ROW_ID is 1 because no Row ID is allocated.
show table t next_row_id;
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
+---------+------------+-------------+--------------------+
| test | t | _tidb_rowid | 1 |
+---------+------------+-------------+--------------------+
1 row in set (0.00 sec)
```

```sql
insert into t values (), (), ();
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
```

```sql
show table t next_row_id;
# Data have been written to the table. The TiDB server that inserts the data allocates and caches 30000 IDs at once. Thus, NEXT_GLOBAL_ROW_ID is 30001 now.
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
+---------+------------+-------------+--------------------+
| test | t | _tidb_rowid | 30001 |
+---------+------------+-------------+--------------------+
1 row in set (0.00 sec)
```

## MySQL compatibility

`SHOW TABLE NEXT_ROW_ID` is specific to TiDB.
12 changes: 6 additions & 6 deletions sql-statements/sql-statement-show-table-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ This statement shows various statistics about tables in TiDB. If the statistics

## Synopsis

**ShowStmt:**
**ShowTableStatusStmt:**

![ShowStmt](/media/sqlgram/ShowStmt.png)
![ShowTableStatusStmt](/media/sqlgram/ShowTableStatusStmt.png)

**ShowTargetFilterable:**
**FromOrIn:**

![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png)
![FromOrIn](/media/sqlgram/FromOrIn.png)

**ShowDatabaseNameOpt:**
**StatusTableName:**

![ShowDatabaseNameOpt](/media/sqlgram/ShowDatabaseNameOpt.png)
![StatusTableName](/media/sqlgram/StatusTableName.png)

## Examples

Expand Down
8 changes: 2 additions & 6 deletions sql-statements/sql-statement-show-warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ This statement shows a list of warnings that occurred for previously executed st

## Synopsis

**ShowStmt:**
**ShowWarningsStmt:**

![ShowStmt](/media/sqlgram/ShowStmt.png)

**ShowTargetFilterable:**

![ShowTargetFilterable](/media/sqlgram/ShowTargetFilterable.png)
![ShowWarningsStmt](/media/sqlgram/ShowWarningsStmt.png)

## Examples

Expand Down