SHOW TABLE NEXT_ROW_ID

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 column created by users.
  • AUTO_RANDOM column created by users.
  • SEQUENCE created by users.

Synopsis

ShowTableNextRowIDStmt

SHOW TABLE NEXT_ROW_ID - 图1

  1. ShowTableNextRowIDStmt ::=
  2. "SHOW" "TABLE" (SchemaName ".")? TableName "NEXT_ROW_ID"

Examples

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

  1. CREATE TABLE t(a int);
  2. Query OK, 0 rows affected (0.06 sec)
  1. SHOW TABLE t NEXT_ROW_ID;
  2. +---------+------------+-------------+--------------------+
  3. | DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
  4. +---------+------------+-------------+--------------------+
  5. | test | t | _tidb_rowid | 1 |
  6. +---------+------------+-------------+--------------------+
  7. 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. The number of IDs is controlled by AUTO_ID_CACHE.

  1. INSERT INTO t VALUES (), (), ();
  2. Query OK, 3 rows affected (0.02 sec)
  3. Records: 3 Duplicates: 0 Warnings: 0
  1. SHOW TABLE t NEXT_ROW_ID;
  2. +---------+------------+-------------+--------------------+
  3. | DB_NAME | TABLE_NAME | COLUMN_NAME | NEXT_GLOBAL_ROW_ID |
  4. +---------+------------+-------------+--------------------+
  5. | test | t | _tidb_rowid | 30001 |
  6. +---------+------------+-------------+--------------------+
  7. 1 row in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also