Skip to content

Instantly share code, notes, and snippets.

@yoku0825
Created September 10, 2022 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoku0825/bb8ce7f57e92e3800f8d9a1492038b27 to your computer and use it in GitHub Desktop.
Save yoku0825/bb8ce7f57e92e3800f8d9a1492038b27 to your computer and use it in GitHub Desktop.
Invisible auto_increment vs LAST_INSERT_ID
mysql80 15> SHOW CREATE TABLE t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`num` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,
`val` varchar(32) COLLATE utf8mb4_ja_0900_as_cs DEFAULT NULL,
UNIQUE KEY `num` (`num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_ja_0900_as_cs
1 row in set (0.00 sec)
mysql80 15>
mysql80 15>
mysql80 15>
mysql80 15> INSERT INTO t1 VALUES ('one');
Query OK, 1 row affected (0.01 sec)
mysql80 15> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql80 15> INSERT INTO t1 VALUES ('two');
Query OK, 1 row affected (0.00 sec)
mysql80 15> SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment