Debian Codegraph @

mysql-test/suite/engines/rr_trx/t/rr_insert_select_2.test

raw
1 ################################################################################
2 #
3 # Executes INSERT ... SELECT statements.
4 #
5 ################################################################################
6
7 SET autocommit = 0;
8 START TRANSACTION;
9
10 # We need this to determine how many rows to update after insert (we may insert mulitple rows).
11 let $pk_before= `SELECT MAX(`pk`) FROM t1`;
12
13 # Insert rows unless we have duplicate values in unique indexes.
14 # WHERE conditions are more or less arbitrary.
15 --error 0, ER_LOCK_DEADLOCK, ER_LOCK_WAIT_TIMEOUT, ER_CHECKREAD, ER_DUP_ENTRY
16 INSERT INTO t1 (`id`, `int1`, `int1_key`, `int1_unique`,
17 `int2`, `int2_key`, `int2_unique`,
18 `for_update`, `is_uncommitted`, `is_consistent`)
19 SELECT src.`id`, src.`int1`, src.`int1_key`, src.`int1_unique`,
20 src.`int2`, src.`int2_key`, src.`int2_unique`,
21 src.`for_update`, src.`is_uncommitted`, src.`is_consistent`
22 FROM t1 AS src
23 WHERE (src.`pk` BETWEEN 1000 AND 1049) AND (src.`id` > 0) AND (src.`is_consistent` = 1) AND (src.`int1_unique` MOD 8 = 0)
24 ON DUPLICATE KEY UPDATE `int1_unique`= src.`int1_unique` + CONNECTION_ID() + 1000, `int2_unique`= src.`int2_unique` - (CONNECTION_ID()+1000);
25
26 --source suite/engines/rr_trx/include/check_for_error_rollback.inc
27
28 # ROW_COUNT may be negative. If positive (and non-zero), update the rows we inserted.
29 let $rows = `SELECT @rows:=ROW_COUNT()`;
30
31 # Make sure $rows is never negative (to avoid infitite loop below).
32 if(`SELECT IF(@rows < 1, 1, 0)`)
33 {
34 let $rows = 0;
35 }
36
37 --echo *** Updating id and connection_id if we actually inserted something (query log disabled)...
38 # Conditional, so skip query log
39 --disable_query_log
40 # We risk duplicate entries... in that case @@last_insert_id is 0
41 while ($rows)
42 {
43 # We actually inserted a row, so update id, conn_id, timestamp
44 --error 0, ER_LOCK_DEADLOCK, ER_LOCK_WAIT_TIMEOUT, ER_CHECKREAD
45 eval UPDATE t1 SET `connection_id` = CONNECTION_ID(), `id` = 2 WHERE `pk` = $pk_before + $rows;
46 --dec $rows
47 }
48 --enable_query_log
49
50 COMMIT;