|
| 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_gtid.inc |
| 92 | +--source include/have_debug.inc |
| 93 | + |
| 94 | +--echo # ==== Initialize ==== |
| 95 | +CREATE TABLE t1 (a INT); |
| 96 | +CREATE TABLE t2 (a INT); |
| 97 | +PREPARE stmt1 FROM 'INSERT INTO t1 VALUES (1)'; |
| 98 | +DELIMITER $; |
| 99 | +CREATE PROCEDURE p1 () |
| 100 | +BEGIN |
| 101 | + INSERT INTO t2 VALUES(2); |
| 102 | +END |
| 103 | +$ |
| 104 | + |
| 105 | +CREATE PROCEDURE p2 () |
| 106 | +BEGIN |
| 107 | + EXECUTE stmt1; |
| 108 | +END |
| 109 | +$ |
| 110 | +DELIMITER ;$ |
| 111 | + |
| 112 | + |
| 113 | +--echo # ==== Case 1 ==== |
| 114 | +--echo # Test case to verify gtid_next update with prepared statement re-prepare. |
| 115 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1'; |
| 116 | +BEGIN; |
| 117 | +EXECUTE stmt1; |
| 118 | +COMMIT; |
| 119 | + |
| 120 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2'; |
| 121 | +TRUNCATE TABLE t1; |
| 122 | + |
| 123 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3'; |
| 124 | +--echo # Without fix, following statement execution fails. |
| 125 | +EXECUTE stmt1; |
| 126 | + |
| 127 | + |
| 128 | +--echo # ==== Case 2 ==== |
| 129 | +--echo # Test case to verify gtid_next update with stored procedure statement |
| 130 | +--echo # re-prepare. |
| 131 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4'; |
| 132 | +CALL p1(); |
| 133 | + |
| 134 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:5'; |
| 135 | +TRUNCATE TABLE t2; |
| 136 | + |
| 137 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:6'; |
| 138 | +--echo # Without fix, following statement execution fails. |
| 139 | +CALL p1(); |
| 140 | + |
| 141 | + |
| 142 | +--echo # ==== Case 3 ==== |
| 143 | +--echo # Test case to verify gtid_next update with prepared statement re-prepare |
| 144 | +--echo # in stored procedure. |
| 145 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:7'; |
| 146 | +CALL p2(); |
| 147 | + |
| 148 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:8'; |
| 149 | +TRUNCATE TABLE t1; |
| 150 | + |
| 151 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:9'; |
| 152 | +--echo # Without fix, following statement execution fails. |
| 153 | +CALL p2(); |
| 154 | + |
| 155 | + |
| 156 | +--echo # === Case 4 === |
| 157 | +--echo # Test case to verify gtid_next update with prepared statement max |
| 158 | +--echo # re-prepare attempt hits. |
| 159 | +SET gtid_next = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:10'; |
| 160 | +TRUNCATE TABLE t1; |
| 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_GROUP |
| 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_GROUP |
| 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; |
0 commit comments