Commit 27ed5bb
Venkatesh Duggirala
BUG#21253415 MULTIPLE DROP TEMP TABLE STATEMENTS IN SF CAUSE REPLICATION
FAILS USING 5.6 GTID
Problem: When there are more than one drop temp table in stored function
or trigger, replication is failing when GTIDs are enabled.
Analysis: In ROW based replication format, even though CREATE TEMPORARY
TABLE query is not replicated, DROP TEMPORARY TABLE queries
are replicated to achieve proper clean up on Slave end (CREATE
TEMPORARY TABLE query would have executed and replicated when
the replication format is STATEMENT) by adding 'IF EXISTS'
clause. When DROP TEMPORARY TABLE query is in a stored function
along with some DML statements, the binlog equivalent query
for that function execution will look like
BEGIN
DROP TEMP TABLE ...
ROW EVENT FOR DML 1
ROW EVENT FOR DML 2
END
But when GTIDs are enabled, it is documented that CREATE/DROP
TEMPORARY TABLE queries are not allowed in Multi Statement
Transactions because half executed gtid transactions (rolled
back of these transactions) can leave these temporary tables
in a bad state.
In the old code, one DROP TEMPORARY TABLE in a function is
working fine because the 'DROP TEMP TABLE' is going into
STMT_CACHE (which does not be wrapped with BEGIN/COMMIT).
//STMT_CACHE
GTID_EVENT
DROP TEMP TABLE ...
//TRANS_CACHE
GTID_EVENT
BEGIN
ROW EVENT FOR DML 1
ROW EVENT FOR DML 2
END
But if the function contains two 'DROP TEMP TABLE's, both
of them are going into 'STMT_CACHE' (which does not be wrapped
with BEGIN/COMMIT) and STMT_CACHE with one gtid_event cannot
accommodate two separate DROP TEMP TABLE queries. And with above
Multi Statement Transactions + GTID restriction, we cannot
add 'BEGIN/COMMIT'.
Fix: Stored functions and Triggers are also considered as another form of
Multi Statement Transactions across the server. To maintain gtid
consistency and to avoid the problems that are mentioned in this bug
scenario, CREATE/DROP temp tables are disallowed from stored functions
and triggers also just like how they were restricted in Multi Statement
Transactions. Now function execution that has CREATE/DROP TEMP TABLES
will throw ER_GTID_UNSAFE_CREATE_DROP_TEMPORARY_TABLE_IN_TRANSACTION.
("When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, the statements CREATE
TEMPORARY TABLE and DROP TEMPORARY TABLE can be executed in a
non-transactional context only, and require that AUTOCOMMIT = 1. These
statements are not allowed in Functions or Triggers also as they are also
considered as Multi Statement transaction.)1 parent c7fb24a commit 27ed5bb
6 files changed
Lines changed: 1441 additions & 6 deletions
File tree
- mysql-test
- extra/rpl_tests
- suite
- binlog/r
- rpl
- r
- t
- sql
Lines changed: 120 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| |||
0 commit comments