From 974a0f458afbc958eb36040f45031a76bd60a589 Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 17 Jun 2020 15:50:47 +0800 Subject: [PATCH 1/2] combine duplicate doc --- .../sql-statement-show-table-next-rowid.md | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sql-statements/sql-statement-show-table-next-rowid.md b/sql-statements/sql-statement-show-table-next-rowid.md index 7deb50fce042b..5c2cddcb9e101 100644 --- a/sql-statements/sql-statement-show-table-next-rowid.md +++ b/sql-statements/sql-statement-show-table-next-rowid.md @@ -6,10 +6,12 @@ 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. +`SHOW TABLE NEXT_ROW_ID` is used to show the details for some special columns, including -- 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. +* `AUTO_INCREMENT` column created automatically, aka `_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 @@ -23,6 +25,8 @@ category: reference ## Examples +For newly created tables, NEXT_GLOBAL_ROW_ID is 1 because no Row ID is allocated. + {{< copyable "sql" >}} ```sql @@ -31,7 +35,6 @@ 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 | @@ -41,6 +44,8 @@ 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. + ```sql insert into t values (), (), (); Query OK, 3 rows affected (0.02 sec) @@ -49,7 +54,6 @@ 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 | +---------+------------+-------------+--------------------+ @@ -61,3 +65,9 @@ show table t next_row_id; ## MySQL compatibility `SHOW TABLE NEXT_ROW_ID` is specific to TiDB. + +## See also + +* [CREATE TABLE](/sql-statements/sql-statement-create-table.md) +* [AUTO_RANDOM](/auto-random.md) +* [CREATE_SEQUENCE](/sql-statements/sql-statement-create-sequence.md) From 7be3dc2100773b9ee71a46026b09e27f846fbab9 Mon Sep 17 00:00:00 2001 From: Keke Yi <40977455+yikeke@users.noreply.github.com> Date: Thu, 18 Jun 2020 13:39:08 +0800 Subject: [PATCH 2/2] Apply suggestions from code review --- sql-statements/sql-statement-show-table-next-rowid.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql-statements/sql-statement-show-table-next-rowid.md b/sql-statements/sql-statement-show-table-next-rowid.md index 5c2cddcb9e101..50047e584637e 100644 --- a/sql-statements/sql-statement-show-table-next-rowid.md +++ b/sql-statements/sql-statement-show-table-next-rowid.md @@ -6,9 +6,9 @@ category: reference # SHOW TABLE NEXT_ROW_ID -`SHOW TABLE NEXT_ROW_ID` is used to show the details for some special columns, including +`SHOW TABLE NEXT_ROW_ID` is used to show the details of some special columns of a table, including: -* `AUTO_INCREMENT` column created automatically, aka `_tidb_rowid` column. +* `AUTO_INCREMENT` 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. @@ -25,7 +25,7 @@ category: reference ## Examples -For newly created tables, NEXT_GLOBAL_ROW_ID is 1 because no Row ID is allocated. +For newly created tables, `NEXT_GLOBAL_ROW_ID` is `1` because no Row ID is allocated. {{< copyable "sql" >}}