From: Date: June 13 2006 5:18pm Subject: bk commit into 5.0 tree (gkodinov:1.2166) BUG#20195 List-Archive: http://lists.mysql.com/commits/7573 X-Bug: 20195 Message-Id: <200606131518.k5DFIdfA023111@localhost.localdomain> Below is the list of changes that have just been committed into a local 5.0 repository of kgeorge. When kgeorge does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2166 06/06/13 18:18:32 gkodinov@stripped +3 -0 Bug #20195: INSERT DELAYED with auto_increment is assigned wrong values The INSERT DELAYED should not maintain its own private auto-increment counter, because this is assuming that other threads cannot insert into the table while the INSERT DELAYED thread is inserting, which is a wrong assumption. So the start of processing of a batch of INSERT rows in the INSERT DELAYED thread must be treated as a start of a new statement and cached next_insert_id must be cleared. sql/sql_insert.cc 1.191 06/06/13 18:18:28 gkodinov@stripped +8 -0 Reset auto-increment cacheing before processing the next batch of inserts in the handler thread mysql-test/t/delayed.test 1.13 06/06/13 18:18:27 gkodinov@stripped +49 -0 test suite for the bug mysql-test/r/delayed.result 1.11 06/06/13 18:18:27 gkodinov@stripped +30 -0 test suite for the bug # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: gkodinov # Host: rakia.(none) # Root: /home/kgeorge/mysql/5.0/B20195 --- 1.190/sql/sql_insert.cc 2006-05-26 11:51:16 +03:00 +++ 1.191/sql/sql_insert.cc 2006-06-13 18:18:28 +03:00 @@ -1938,6 +1938,14 @@ if (!using_bin_log) table->file->extra(HA_EXTRA_WRITE_CACHE); pthread_mutex_lock(&mutex); + + /* Reset auto-increment cacheing */ + if (thd.clear_next_insert_id) + { + thd.next_insert_id= 0; + thd.clear_next_insert_id= 0; + } + while ((row=rows.get())) { stacked_inserts--; --- 1.10/mysql-test/r/delayed.result 2005-08-02 03:00:00 +03:00 +++ 1.11/mysql-test/r/delayed.result 2006-06-13 18:18:27 +03:00 @@ -39,3 +39,33 @@ a 1 drop table t1; +CREATE TABLE t1 ( a int(10) NOT NULL auto_increment, PRIMARY KEY (a)); +insert delayed into t1 values(null); +insert into t1 values(null); +insert into t1 values(null); +insert delayed into t1 values(null); +insert delayed into t1 values(null); +insert delayed into t1 values(null); +insert into t1 values(null); +insert into t1 values(null); +insert into t1 values(null); +delete from t1 where a=6; +insert delayed into t1 values(null); +insert delayed into t1 values(null); +insert delayed into t1 values(null); +insert delayed into t1 values(null); +select * from t1 order by a; +a +1 +2 +3 +4 +5 +7 +8 +9 +10 +11 +12 +13 +DROP TABLE t1; --- 1.12/mysql-test/t/delayed.test 2006-02-24 18:34:08 +02:00 +++ 1.13/mysql-test/t/delayed.test 2006-06-13 18:18:27 +03:00 @@ -50,3 +50,52 @@ insert delayed into t1 values (1); select * from t1; drop table t1; + +# +# Bug #20195: INSERT DELAYED with auto_increment is assigned wrong values +# +CREATE TABLE t1 ( a int(10) NOT NULL auto_increment, PRIMARY KEY (a)); + +# Make one delayed insert to start the separate thread +insert delayed into t1 values(null); + +# Do some normal inserts +insert into t1 values(null); +insert into t1 values(null); + +# Discarded, since the delayed-counter is 2, which is already used +insert delayed into t1 values(null); + +# Discarded, since the delayed-counter is 3, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 4, which is unused +insert delayed into t1 values(null); + +# Do some more inserts +insert into t1 values(null); +insert into t1 values(null); +insert into t1 values(null); + +# Delete one of the above to make a hole +delete from t1 where a=6; + +# Discarded, since the delayed-counter is 5, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 6, which is unused (the row we deleted) +insert delayed into t1 values(null); + +# Discarded, since the delayed-counter is 7, which is already used +insert delayed into t1 values(null); + +# Works, since the delayed-counter is 8, which is unused +insert delayed into t1 values(null); + +# Check what we have now +# must wait so that the delayed thread finishes +# Note: this must be increased if the test fails +--sleep 1 +select * from t1 order by a; + +DROP TABLE t1;