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

ebnf show table next rowid #17093

Merged
merged 2 commits into from
Apr 22, 2024
Merged
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
25 changes: 10 additions & 15 deletions sql-statements/sql-statement-show-table-next-rowid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@ aliases: ['/docs/dev/sql-statements/sql-statement-show-table-next-rowid/']

`SHOW TABLE NEXT_ROW_ID` is used to show the details of some special columns of a table, including:

* `AUTO_INCREMENT` column automatically created by TiDB, namely, `_tidb_rowid` column.
* [`AUTO_INCREMENT`](/auto-increment.md) column automatically created by TiDB, namely, `_tidb_rowid` column.
* `AUTO_INCREMENT` column created by users.
* [`AUTO_RANDOM`](/auto-random.md) column created by users.
* [`SEQUENCE`](/sql-statements/sql-statement-create-sequence.md) created by users.

## Synopsis

**ShowTableNextRowIDStmt:**

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

**TableName:**

![TableName](/media/sqlgram/TableName.png)
```ebnf+diagram
ShowTableNextRowIDStmt ::=
"SHOW" "TABLE" (SchemaName ".")? TableName "NEXT_ROW_ID"
```

## Examples

For newly created tables, `NEXT_GLOBAL_ROW_ID` is `1` because no Row ID is allocated.

{{< copyable "sql" >}}

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

```sql
show table t next_row_id;
SHOW TABLE t NEXT_ROW_ID;
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
+---------+------------+-------------+--------------------+
Expand All @@ -44,16 +39,16 @@ show table t next_row_id;
1 row in set (0.00 sec)
```

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.
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. The number of IDs is controlled by [`AUTO_ID_CACHE`](/auto-increment.md#auto_id_cache).

```sql
insert into t values (), (), ();
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;
SHOW TABLE t NEXT_ROW_ID;
+---------+------------+-------------+--------------------+
| DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
+---------+------------+-------------+--------------------+
Expand Down
Loading