Loading mysql-test/r/rpl_insert_id.result +18 −0 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ DROP TABLE t1, t2; DROP PROCEDURE IF EXISTS p1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP FUNCTION IF EXISTS f3; DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Loading @@ -295,6 +296,11 @@ RETURN 0; END | CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC RETURN LAST_INSERT_ID() | CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA BEGIN INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); RETURN 0; END | INSERT INTO t1 VALUES (NULL, -1); CALL p1(); SELECT f1(); Loading @@ -307,6 +313,11 @@ 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; INSERT INTO t1 (i) VALUES (NULL); INSERT INTO t1 (i) VALUES (NULL); SELECT f3(); f3() 0 SELECT * FROM t1; i j 1 -1 Loading @@ -327,12 +338,15 @@ i j 16 13 17 -1 18 14 19 0 20 0 SELECT * FROM t2; i 2 3 5 6 19 SELECT * FROM t1; i j 1 -1 Loading @@ -353,15 +367,19 @@ i j 16 13 17 -1 18 14 19 0 20 0 SELECT * FROM t2; i 2 3 5 6 19 DROP PROCEDURE p1; DROP FUNCTION f1; DROP FUNCTION f2; DROP FUNCTION f3; DROP TABLE t1, t2; # End of 5.0 tests Loading mysql-test/t/rpl_insert_id.test +17 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,7 @@ DROP TABLE t1, t2; DROP PROCEDURE IF EXISTS p1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP FUNCTION IF EXISTS f3; DROP TABLE IF EXISTS t1, t2; --enable_warnings Loading Loading @@ -328,6 +329,12 @@ END | CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC RETURN LAST_INSERT_ID() | CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA BEGIN INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); RETURN 0; END | delimiter ;| INSERT INTO t1 VALUES (NULL, -1); Loading @@ -342,6 +349,15 @@ INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)), INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID()); UPDATE t1 SET j= -1 WHERE i IS NULL; # Test statement-based replication of function calls. INSERT INTO t1 (i) VALUES (NULL); connection master1; INSERT INTO t1 (i) VALUES (NULL); connection master; SELECT f3(); SELECT * FROM t1; SELECT * FROM t2; Loading @@ -353,6 +369,7 @@ connection master; DROP PROCEDURE p1; DROP FUNCTION f1; DROP FUNCTION f2; DROP FUNCTION f3; DROP TABLE t1, t2; Loading sql/item_func.cc +1 −0 Original line number Diff line number Diff line Loading @@ -3362,6 +3362,7 @@ bool Item_func_last_insert_id::fix_fields(THD *thd, Item **ref) id of the previous statement in THD::current_insert_id. */ thd->last_insert_id_used= TRUE; thd->last_insert_id_used_bin_log= TRUE; thd->current_insert_id= thd->last_insert_id; } null_value= FALSE; Loading sql/log.cc +2 −2 Original line number Diff line number Diff line Loading @@ -1702,7 +1702,7 @@ bool MYSQL_LOG::write(Log_event *event_info) if (thd) { if (thd->last_insert_id_used) if (thd->last_insert_id_used_bin_log) { Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT, thd->current_insert_id); Loading Loading @@ -1994,7 +1994,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, tmp_errno=errno; strmov(db,thd->db); } if (thd->last_insert_id_used) if (thd->last_insert_id_used_bin_log) { end=strmov(end,",last_insert_id="); end=longlong10_to_str((longlong) thd->current_insert_id,end,-10); Loading sql/set_var.cc +1 −0 Original line number Diff line number Diff line Loading @@ -2579,6 +2579,7 @@ byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type, of the previous statement in THD::current_insert_id. */ thd->last_insert_id_used= TRUE; thd->last_insert_id_used_bin_log= TRUE; thd->current_insert_id= thd->last_insert_id; } return (byte*) &thd->current_insert_id; Loading Loading
mysql-test/r/rpl_insert_id.result +18 −0 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ DROP TABLE t1, t2; DROP PROCEDURE IF EXISTS p1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP FUNCTION IF EXISTS f3; DROP TABLE IF EXISTS t1, t2; CREATE TABLE t1 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, Loading @@ -295,6 +296,11 @@ RETURN 0; END | CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC RETURN LAST_INSERT_ID() | CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA BEGIN INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); RETURN 0; END | INSERT INTO t1 VALUES (NULL, -1); CALL p1(); SELECT f1(); Loading @@ -307,6 +313,11 @@ 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; INSERT INTO t1 (i) VALUES (NULL); INSERT INTO t1 (i) VALUES (NULL); SELECT f3(); f3() 0 SELECT * FROM t1; i j 1 -1 Loading @@ -327,12 +338,15 @@ i j 16 13 17 -1 18 14 19 0 20 0 SELECT * FROM t2; i 2 3 5 6 19 SELECT * FROM t1; i j 1 -1 Loading @@ -353,15 +367,19 @@ i j 16 13 17 -1 18 14 19 0 20 0 SELECT * FROM t2; i 2 3 5 6 19 DROP PROCEDURE p1; DROP FUNCTION f1; DROP FUNCTION f2; DROP FUNCTION f3; DROP TABLE t1, t2; # End of 5.0 tests Loading
mysql-test/t/rpl_insert_id.test +17 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,7 @@ DROP TABLE t1, t2; DROP PROCEDURE IF EXISTS p1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP FUNCTION IF EXISTS f3; DROP TABLE IF EXISTS t1, t2; --enable_warnings Loading Loading @@ -328,6 +329,12 @@ END | CREATE FUNCTION f2() RETURNS INT NOT DETERMINISTIC RETURN LAST_INSERT_ID() | CREATE FUNCTION f3() RETURNS INT MODIFIES SQL DATA BEGIN INSERT INTO t2 (i) VALUES (LAST_INSERT_ID()); RETURN 0; END | delimiter ;| INSERT INTO t1 VALUES (NULL, -1); Loading @@ -342,6 +349,15 @@ INSERT INTO t1 VALUES (NULL, LAST_INSERT_ID()), (NULL, LAST_INSERT_ID(5)), INSERT INTO t1 VALUES (NULL, 0), (NULL, LAST_INSERT_ID()); UPDATE t1 SET j= -1 WHERE i IS NULL; # Test statement-based replication of function calls. INSERT INTO t1 (i) VALUES (NULL); connection master1; INSERT INTO t1 (i) VALUES (NULL); connection master; SELECT f3(); SELECT * FROM t1; SELECT * FROM t2; Loading @@ -353,6 +369,7 @@ connection master; DROP PROCEDURE p1; DROP FUNCTION f1; DROP FUNCTION f2; DROP FUNCTION f3; DROP TABLE t1, t2; Loading
sql/item_func.cc +1 −0 Original line number Diff line number Diff line Loading @@ -3362,6 +3362,7 @@ bool Item_func_last_insert_id::fix_fields(THD *thd, Item **ref) id of the previous statement in THD::current_insert_id. */ thd->last_insert_id_used= TRUE; thd->last_insert_id_used_bin_log= TRUE; thd->current_insert_id= thd->last_insert_id; } null_value= FALSE; Loading
sql/log.cc +2 −2 Original line number Diff line number Diff line Loading @@ -1702,7 +1702,7 @@ bool MYSQL_LOG::write(Log_event *event_info) if (thd) { if (thd->last_insert_id_used) if (thd->last_insert_id_used_bin_log) { Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT, thd->current_insert_id); Loading Loading @@ -1994,7 +1994,7 @@ bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, tmp_errno=errno; strmov(db,thd->db); } if (thd->last_insert_id_used) if (thd->last_insert_id_used_bin_log) { end=strmov(end,",last_insert_id="); end=longlong10_to_str((longlong) thd->current_insert_id,end,-10); Loading
sql/set_var.cc +1 −0 Original line number Diff line number Diff line Loading @@ -2579,6 +2579,7 @@ byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type, of the previous statement in THD::current_insert_id. */ thd->last_insert_id_used= TRUE; thd->last_insert_id_used_bin_log= TRUE; thd->current_insert_id= thd->last_insert_id; } return (byte*) &thd->current_insert_id; Loading