1SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
2SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
3CREATE TABLE t1(c1 VARCHAR(10) NOT NULL, c2 VARCHAR(10) NOT NULL, c3 VARCHAR(10) NOT NULL);
4INSERT INTO t1(c1, c2, c3) VALUES('A1','B1','IT1'), ('A2','B2','IT1'), ('A3','B3','IT1'), ('A4','B4','IT1'), ('A5','B5','IT1'), ('A6','B6','IT1'), ('A7','B7','IT1');
5CREATE TABLE t2(c1 VARCHAR(10) NOT NULL, c2 VARCHAR(10) NOT NULL, c3 VARCHAR(10) NOT NULL);
6INSERT INTO t2(c1, c2, c3) VALUES ('A3','B3','IT2'), ('A2','B2','IT2'), ('A4','B4','IT2'), ('A5','B5','II2');
7CREATE TABLE result(id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, c1 VARCHAR(10) NOT NULL, c2 VARCHAR(10),
8c3 VARCHAR(10), update_count INT DEFAULT 0, UNIQUE KEY uniq_idx (c1,c2), PRIMARY KEY (id)) ENGINE = innodb;
9SET DEBUG_SYNC = "ha_write_row_end WAIT_FOR flushed EXECUTE 1";
10INSERT INTO result(c1, c2, c3) SELECT * FROM t1 ON DUPLICATE KEY UPDATE c2=t1.c2, c3='UT1', update_count=update_count+1;
11INSERT INTO result(c1, c2, c3) SELECT * FROM t2 ON DUPLICATE KEY UPDATE c2=t2.c2, c3='UT2', update_count=update_count+1;
12SET DEBUG_SYNC = "now SIGNAL flushed";
13SELECT * FROM result;
14id	c1	c2	c3	update_count
151	A1	B1	IT1	0
162	A3	B3	UT1	1
173	A2	B2	UT1	1
184	A4	B4	UT1	1
195	A5	B5	UT1	1
209	A6	B6	IT1	0
2110	A7	B7	IT1	0
22DROP TABLE t1;
23DROP TABLE t2;
24DROP TABLE result;
25