Bug #35386 Insert delayed statements insert 1 + limit records instead of just limit records
Submitted: 18 Mar 2008 9:39 Modified: 18 Mar 2008 21:36
Reporter: Rizwan Maredia Email Updates:
Status: Verified
Category:Server: DML Severity:S3 (Non-critical)
Version:5.1.22 OS:Any
Assigned to: Target Version:
Tags: insert delayed, delayed_insert_limit
Triage: Triaged: D3 (Medium)

[18 Mar 2008 9:39] Rizwan Maredia
Description:
If an insert delayed statements are queued and there has been a limit set on max insert
delayed statements to be executed at once. The insert delayed statements that actually
get executed are 1 more than the limit set.

How to repeat:
Here is how can reproduce this bug in mysql test environment

CREATE TABLE t1 (a varchar(10));
SET GLOBAL delayed_insert_limit = 2;

connect (con0,localhost,root,,);
connect (con1,localhost,root,,);

connection default;
LOCK TABLE t1 WRITE;

connection con1;

delimiter |;
send
INSERT DELAYED INTO t1 VALUES('1');
INSERT DELAYED INTO t1 VALUES('2');
INSERT DELAYED INTO t1 VALUES('3');
INSERT DELAYED INTO t1 VALUES('4');
INSERT DELAYED INTO t1 VALUES('5');|
delimiter ;|

connection con0;
send SELECT * FROM t1;

connection default;
--sleep 1
UNLOCK TABLES;

connection con0;
reap;

# the reap outputs following result

a
1
2
3

This shows that 3 records are inserted instead of 2.

Suggested fix:
The number of executed delayed inserts executed should be equal to the limit provided.
[18 Mar 2008 21:36] Sveta Smirnova
Thank you for the report.

Verified as described.
[20 Mar 2008 20:47] Omer BarNir
Workaround: Set limit to x-1