Bug #16689 | LAST_INSERT_ID() not stable within statement | ||
---|---|---|---|
Submitted: | 20 Jan 2006 22:31 | Modified: | 31 Jan 2006 7:56 |
Reporter: | Paul DuBois | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1.2 and up | OS: | Any (all) |
Assigned to: | CPU Architecture: | Any |
[20 Jan 2006 22:31]
Paul DuBois
[20 Jan 2006 23:44]
MySQL Verification Team
miguel@hegel:~/dbs/5.0> bin/mysql -uroot test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.0.19-debug Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> CREATE TABLE parent ( -> p_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, -> PRIMARY KEY (p_id) -> ); Query OK, 0 rows affected (0.01 sec) mysql> mysql> CREATE TABLE child ( -> c_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, -> p_id SMALLINT UNSIGNED NOT NULL, -> KEY (c_id) -> ); Query OK, 0 rows affected (0.00 sec) mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()); Query OK, 1 row affected (0.00 sec) mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> mysql> SELECT * FROM parent; +------+ | p_id | +------+ | 1 | | 2 | | 3 | | 4 | +------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM child; +------+------+ | c_id | p_id | +------+------+ | 1 | 1 | | 2 | 2 | | 3 | 2 | | 4 | 3 | | 5 | 4 | | 6 | 5 | | 7 | 4 | | 8 | 7 | | 9 | 8 | | 10 | 9 | +------+------+ 10 rows in set (0.00 sec) mysql> c:\mysql\bin>mysql -uroot test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.1.1-alpha-nt Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> CREATE TABLE parent ( -> p_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, -> PRIMARY KEY (p_id) -> ); Query OK, 0 rows affected (0.06 sec) mysql> mysql> CREATE TABLE child ( -> c_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, -> p_id SMALLINT UNSIGNED NOT NULL, -> KEY (c_id) -> ); Query OK, 0 rows affected (0.05 sec) mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()); Query OK, 1 row affected (0.02 sec) mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 2 rows affected (0.00 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.02 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> mysql> INSERT INTO parent VALUES (NULL); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO child VALUES -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()), -> (NULL, LAST_INSERT_ID()); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> mysql> SELECT * FROM parent; +------+ | p_id | +------+ | 1 | | 2 | | 3 | | 4 | +------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM child; +------+------+ | c_id | p_id | +------+------+ | 1 | 1 | | 2 | 2 | | 3 | 2 | | 4 | 3 | | 5 | 3 | | 6 | 3 | | 7 | 4 | | 8 | 4 | | 9 | 4 | | 10 | 4 | +------+------+ 10 rows in set (0.01 sec) mysql>
[31 Jan 2006 7:56]
Calvin Sun
A duplicate of bug#6880.