1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

BUG#21726: Incorrect result with multiple invocations of LAST_INSERT_ID.

Note: bug#21726 does not directly apply to 4.1, as it doesn't have stored
procedures.  However, 4.1 had some bugs that were fixed in 5.0 by the
patch for bug#21726, and this patch is a backport of those fixes.
Namely, in 4.1 it fixes:

  - LAST_INSERT_ID(expr) didn't return value of expr (4.1 specific).

  - LAST_INSERT_ID() could return the value generated by current
    statement if the call happens after the generation, like in

      CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT);
      INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID());

  - Redundant binary log LAST_INSERT_ID_EVENTs could be generated.
This commit is contained in:
kroki/tomash@moonlight.intranet
2006-10-06 13:34:07 +04:00
parent acaa584c55
commit ee0cebf9a7
13 changed files with 189 additions and 38 deletions

View File

@@ -108,6 +108,33 @@ a
1
drop table t1;
drop table t2;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
j INT DEFAULT 0
);
INSERT INTO t1 VALUES (NULL, -1);
INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)),
(NULL, @@LAST_INSERT_ID);
INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID());
UPDATE t1 SET j= -1 WHERE i IS NULL;
SELECT * FROM t1;
i j
1 -1
2 1
3 5
4 1
5 -1
6 2
SELECT * FROM t1;
i j
1 -1
2 1
3 5
4 1
5 -1
6 2
DROP TABLE t1;
#
# End of 4.1 tests
#