| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# If re-prepare of a prepared statement or statement in stored program is |
| 4 |
# triggered then gtid_next should not be updated. Tests in this file verifies |
| 5 |
# gtid_next value update with prepared statement and stored procedure |
| 6 |
# re-prepare. Re-prepare statement code is same for all the stored programs. So |
| 7 |
# behavior is verified with only stored procedure in this file. |
| 8 |
# |
| 9 |
# ==== Requirements ==== |
| 10 |
# |
| 11 |
# When a session has set GTID_NEXT to a UUID:NUMBER and AUTOCOMMIT is enabled, |
| 12 |
# the following requirements shall hold: |
| 13 |
# |
| 14 |
# R1. If a statement is re-prepared, it shall leave GTID_NEXT unchanged: |
| 15 |
# |
| 16 |
# R1.1. For prepared statements (EXECUTE) |
| 17 |
# R1.2. For stored procedures (CALL) |
| 18 |
# |
| 19 |
# R2. If a statement exhausts the re-prepare count so that it fails with |
| 20 |
# ER_NEED_REPREPARE, it shall set GTID_NEXT to UNDEFINED: |
| 21 |
# |
| 22 |
# R2.1. For prepared statements (EXECUTE) |
| 23 |
# R2.2. For stored procedures (CALL) |
| 24 |
# |
| 25 |
# ==== Implementation ==== |
| 26 |
# |
| 27 |
# Initialize |
| 28 |
# a) create table |
| 29 |
# b) create prepared statement and stored procedure using table created |
| 30 |
# in step a. |
| 31 |
# |
| 32 |
# 1) Verify behavior with a prepared statement |
| 33 |
# 1.1) SET gtid_next = UUID:NUMBER |
| 34 |
# 1.2) Execute prepared statement. |
| 35 |
# 1.3) SET gtid_next = UUID:NUMBER |
| 36 |
# 1.4) Truncate table so that table version is updated. |
| 37 |
# 1.5) SET gtid_next = UUID:NUMBER |
| 38 |
# 1.6) Re-execute prepared statement. Statement re-prepare is triggered |
| 39 |
# as table version is changed. This operation should *not* invalidate |
| 40 |
# gtid_next. |
| 41 |
# |
| 42 |
# 2) Verify behavior with a stored procedure. |
| 43 |
# 2.1) SET gtid_next = UUID:NUMBER |
| 44 |
# 2.2) Execute stored procedure. |
| 45 |
# 2.3) SET gtid_next = UUID:NUMBER |
| 46 |
# 2.4) Truncate table so that table version is updated. |
| 47 |
# 2.5) SET gtid_next = UUID:NUMBER |
| 48 |
# 2.6) Re-execute stored procedure. Statement re-prepare is triggered as |
| 49 |
# table version is changed. This operation should *not* invalidate |
| 50 |
# gtid_next. |
| 51 |
# |
| 52 |
# 3) Verify behavior with a prepared statement in stored procedure. |
| 53 |
# 3.1) SET gtid_next = UUID:NUMBER |
| 54 |
# 3.2) Execute stored procedure. |
| 55 |
# 3.3) SET gtid_next = UUID:NUMBER |
| 56 |
# 3.4) Truncate table so that table version is updated. |
| 57 |
# 3.5) SET gtid_next = UUID:NUMBER |
| 58 |
# 3.6) Re-execute stored procedure. Statement re-prepare is triggered as |
| 59 |
# table version is changed. This operation should *not* invalidate |
| 60 |
# gtid_next. |
| 61 |
# |
| 62 |
# 4) Verify behavior with a prepared statement in max re-prepare hit situation. |
| 63 |
# 4.1) SET gtid_next = UUID:NUMBER |
| 64 |
# 4.2) Execute prepared statement. |
| 65 |
# 4.3) SET gtid_next = UUID:NUMBER |
| 66 |
# 4.4) Truncate table so that table version is updated. |
| 67 |
# 4.5) SET gtid_next = UUID:NUMBER |
| 68 |
# 4.6) Simulate max prepared statement re-prepare hit condition. |
| 69 |
# 4.7) Re-execute prepared statement. Statement re-prepare is triggered as |
| 70 |
# table version is changed. This operation fails and gtid_next is |
| 71 |
# invalidated. |
| 72 |
# |
| 73 |
# 5) Verify behavior with a stored procedure in max re-prepare hit situation. |
| 74 |
# 5.1) SET gtid_next = UUID:NUMBER |
| 75 |
# 5.2) Execute stored procedure. |
| 76 |
# 5.3) SET gtid_next = UUID:NUMBER |
| 77 |
# 5.4) Truncate table so that table version is updated. |
| 78 |
# 5.5) SET gtid_next = UUID:NUMBER |
| 79 |
# 5.6) Simulate max prepared statement re-prepare hit condition. |
| 80 |
# 5.7) Re-execute stored procedure. Statement re-prepare is triggered as |
| 81 |
# table version is changed. This operation fails and gtid_next is |
| 82 |
# invalidated. |
| 83 |
# |
| 84 |
# |
| 85 |
# ==== References ==== |
| 86 |
# |
| 87 |
# Bug#32326510 - REPREPARE AT THE BEGINNING OF AN IMPLICIT TRANS WILL CAUSE 1837 |
| 88 |
# ERROR. |
| 89 |
# |
| 90 |
|
| 91 |
--source include/have_debug.inc |
| 92 |
|
| 93 |
--echo # ==== Initialize ==== |
| 94 |
CREATE TABLE t1 (a INT); |
| 95 |
CREATE TABLE t2 (a INT); |
| 96 |
PREPARE stmt1 FROM 'INSERT INTO t1 VALUES (1)'; |
| 97 |
DELIMITER $; |
| 98 |
CREATE PROCEDURE p1 () |
| 99 |
BEGIN |
| 100 |
INSERT INTO t2 VALUES(2); |
| 101 |
END |
| 102 |
$ |
| 103 |
|
| 104 |
CREATE PROCEDURE p2 () |
| 105 |
BEGIN |
| 106 |
EXECUTE stmt1; |
| 107 |
END |
| 108 |
$ |
| 109 |
DELIMITER ;$ |
| 110 |
|
| 111 |
|
| 112 |
--echo # ==== Case 1 ==== |
| 113 |
--echo # Test case to verify gtid_next update with prepared statement re-prepare. |
| 114 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1'; |
| 115 |
BEGIN; |
| 116 |
EXECUTE stmt1; |
| 117 |
COMMIT; |
| 118 |
|
| 119 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2'; |
| 120 |
TRUNCATE TABLE t1; |
| 121 |
|
| 122 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3'; |
| 123 |
--echo # Without fix, following statement execution fails. |
| 124 |
EXECUTE stmt1; |
| 125 |
|
| 126 |
|
| 127 |
--echo # ==== Case 2 ==== |
| 128 |
--echo # Test case to verify gtid_next update with stored procedure statement |
| 129 |
--echo # re-prepare. |
| 130 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4'; |
| 131 |
CALL p1(); |
| 132 |
|
| 133 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:5'; |
| 134 |
TRUNCATE TABLE t2; |
| 135 |
|
| 136 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:6'; |
| 137 |
--echo # Without fix, following statement execution fails. |
| 138 |
CALL p1(); |
| 139 |
|
| 140 |
|
| 141 |
--echo # ==== Case 3 ==== |
| 142 |
--echo # Test case to verify gtid_next update with prepared statement re-prepare |
| 143 |
--echo # in stored procedure. |
| 144 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:7'; |
| 145 |
CALL p2(); |
| 146 |
|
| 147 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:8'; |
| 148 |
TRUNCATE TABLE t1; |
| 149 |
|
| 150 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:9'; |
| 151 |
--echo # Without fix, following statement execution fails. |
| 152 |
CALL p2(); |
| 153 |
|
| 154 |
|
| 155 |
--echo # === Case 4 === |
| 156 |
--echo # Test case to verify gtid_next update with prepared statement max |
| 157 |
--echo # re-prepare attempt hits. |
| 158 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:10'; |
| 159 |
TRUNCATE TABLE t1; |
| 160 |
|
| 161 |
|
| 162 |
--let $debug_point= simulate_max_reprepare_attempts_hit_case |
| 163 |
--let $debug_type= SESSION |
| 164 |
--source include/add_debug_point.inc |
| 165 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:11'; |
| 166 |
--echo # Error is reported when max re-prepare limit is hit. Transaction is |
| 167 |
--echo # rolled back and gtid_next is updated. |
| 168 |
--error ER_NEED_REPREPARE |
| 169 |
EXECUTE stmt1; |
| 170 |
--error ER_GTID_NEXT_TYPE_UNDEFINED_GTID |
| 171 |
INSERT INTO t1 VALUES(10); |
| 172 |
|
| 173 |
|
| 174 |
--echo # === Case 5 === |
| 175 |
--echo # Test case to verify gtid_next update with stored procedure statement |
| 176 |
--echo # max re-prepare attempt hits. |
| 177 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:12'; |
| 178 |
TRUNCATE TABLE t2; |
| 179 |
|
| 180 |
SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:13'; |
| 181 |
--echo # Error is reported when max re-prepare limit is hit. Transaction is |
| 182 |
--echo # rolled back and gtid_next is updated. |
| 183 |
--error ER_NEED_REPREPARE |
| 184 |
CALL p1; |
| 185 |
--error ER_GTID_NEXT_TYPE_UNDEFINED_GTID |
| 186 |
INSERT INTO t2 VALUES(10); |
| 187 |
|
| 188 |
|
| 189 |
--echo # ==== Cleanup ==== |
| 190 |
SET gtid_next = DEFAULT; |
| 191 |
--let $debug_point= simulate_max_reprepare_attempts_hit_case |
| 192 |
--let $debug_type= SESSION |
| 193 |
--source include/remove_debug_point.inc |
| 194 |
DEALLOCATE PREPARE stmt1; |
| 195 |
DROP TABLE t1, t2; |
| 196 |
DROP PROCEDURE p1; |
| 197 |
DROP PROCEDURE p2; |