summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/galera/t/ev51914.test
blob: e5edacabe895a3c2c4091784def70eccc6f6c2a8 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Disable SAVEPOINT and ROLLBACK TO SAVEPOINT in SP, SF, TR.

--source include/galera_cluster.inc
--source include/have_innodb.inc


--connection node_1
--echo SAVEPOINT in a stored function should be forbidden
--delimiter |
CREATE FUNCTION f1 () RETURNS INT BEGIN
       SAVEPOINT s;
       RETURN 1;
END|
--delimiter ;

SELECT f1();

DROP FUNCTION f1;

--echo ROLLBACK TO SAVEPOINT in a stored function should be forbidden
--delimiter |
CREATE FUNCTION f2 () RETURNS INT BEGIN
       ROLLBACK TO SAVEPOINT s;
       RETURN 1;
END|
--delimiter ;

BEGIN;
SAVEPOINT s;
--error ER_SP_DOES_NOT_EXIST
SELECT f2();
COMMIT;

DROP FUNCTION f2;

BEGIN;
SAVEPOINT S;
ROLLBACK TO SAVEPOINT S;
COMMIT;


CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE t2 (a INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
INSERT INTO t1 values (110), (111), (112), (113), (114);

--echo Direct SAVEPOINT in a trigger should be forbidden
--connection node_2
CREATE TRIGGER i1_t1 BEFORE INSERT ON t1 FOR EACH ROW SAVEPOINT s;

--connection node_1
INSERT INTO t1 VALUES (1);
DROP TRIGGER i1_t1;

CREATE TRIGGER i2_t1 AFTER INSERT ON t1 FOR EACH ROW SAVEPOINT s;
INSERT INTO t1 VALUES (2);
DROP TRIGGER i2_t1;

INSERT INTO t1 VALUES (3);
CREATE TRIGGER u1_t1 BEFORE UPDATE ON t1 FOR EACH ROW SAVEPOINT s;
UPDATE t1 SET a=4 WHERE a=3;
DROP TRIGGER u1_t1;

CREATE TRIGGER u2_t1 AFTER UPDATE ON t1 FOR EACH ROW SAVEPOINT s;
UPDATE t1 SET a=4 WHERE a=3;
DROP TRIGGER u2_t1;

CREATE TRIGGER d1_t1 BEFORE DELETE ON t1 FOR EACH ROW SAVEPOINT s;
DELETE FROM t1;
DROP TRIGGER d1_t1;

CREATE TRIGGER d1_t1 AFTER DELETE ON t1 FOR EACH ROW SAVEPOINT s;
DELETE FROM t1;
DROP TRIGGER d1_t1;

--echo SAVEPOINT in a compound statement in a trigger should be forbidden
--delimiter |
CREATE TRIGGER i3_t1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN
       SAVEPOINT s;
END|
--delimiter ;
INSERT INTO t1 VALUES (5);
DROP TRIGGER i3_t1;

--echo SAVEPOINT in a PS call in a trigger should be forbidden
# echo handled by SAVEPOINT forbidden in PS
--delimiter |
--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
CREATE TRIGGER i4_t1 BEFORE INSERT ON t1 FOR EACH ROW BEGIN
       PREPARE set_savepoint FROM "SAVEPOINT s";
       EXECUTE set_savepoint;
       DEALLOCATE PREPARE set_savepoint;
END|
--delimiter ;

--connection node_2
--echo SAVEPOINT in SP called from a trigger should be forbidden
--delimiter |
CREATE PROCEDURE p1() BEGIN
       SAVEPOINT s;
END|
--delimiter ;
--connection node_1
CREATE TRIGGER i5_t1 BEFORE INSERT ON t1 FOR EACH ROW CALL p1;
INSERT INTO t1 VALUES (6);
DROP TRIGGER i5_t1;

--echo SAVEPOINT in a SP called from a PS called from a trigger be forbidden
# echo handled by SAVEPOINT forbidden in PS
PREPARE call_p1 FROM "CALL p1";
--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG
CREATE TRIGGER i6_t1 BEFORE INSERT ON t1 FOR EACH ROW EXECUTE call_p1;

--echo SAVEPOINT in a function called from a trigger should be forbidden
--delimiter |
CREATE FUNCTION f1 () RETURNS INT BEGIN
       SAVEPOINT s;
       RETURN 1;
END|
--delimiter ;
CREATE TRIGGER i7_t1 BEFORE INSERT ON t1 FOR EACH ROW SET @foo = f1();
INSERT INTO t1 VALUES (7);
DROP TRIGGER i7_t1;

--echo SAVEPOINT in a SP called from a SP called from a trigger should be forbidden
--delimiter |
CREATE PROCEDURE p2() BEGIN
       CALL p1();
END|
--delimiter ;
CREATE TRIGGER i8_t1 BEFORE INSERT ON t1 FOR EACH ROW CALL p2;
INSERT INTO t1 VALUES (8);
DROP TRIGGER i8_t1;

--echo SAVEPOINT in a SP called from a trigger called from a SP should be forbidden
CREATE TRIGGER i9_t1 BEFORE INSERT ON t1 FOR EACH ROW CALL p1;
--delimiter |
CREATE PROCEDURE p3() BEGIN
       INSERT INTO t1 VALUES (9);
END|
--delimiter ;
CALL p3();
DROP TRIGGER i9_t1;

--echo ROLLBACK TO SAVEPOINT in trigger as a trivial statement should be forbidden
# Trigger activation creates a new savepoint level, making the earlier levels
# inaccessible. Thus forbidding SAVEPOINT should be enough as then there is
# no valid savepoint to pass to ROLLBACK TO SAVEPOINT, but we forbid it once
# more just in case.
CREATE TRIGGER i4_t1 BEFORE INSERT ON t1 FOR EACH ROW ROLLBACK TO SAVEPOINT s;
BEGIN;
SAVEPOINT s;
--error ER_SP_DOES_NOT_EXIST
INSERT INTO t1 VALUES (5);
COMMIT;
DROP TRIGGER i4_t1;

--echo ROLLBACK TO SAVEPOINT in a trigger in a SP call should be forbidden
--delimiter |
CREATE PROCEDURE p4() BEGIN
       ROLLBACK TO SAVEPOINT s;
END|
--delimiter ;
CREATE TRIGGER i5_t1 BEFORE INSERT ON t1 FOR EACH ROW CALL p4;
BEGIN;
SAVEPOINT s;
--error ER_SP_DOES_NOT_EXIST
INSERT INTO t1 VALUES (6);
COMMIT;
DROP TRIGGER i5_t1;

--echo SAVEPOINT in a SP next to a trigger should work
CREATE TRIGGER i6_t1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a = NEW.a + 1;
--delimiter |
CREATE PROCEDURE p5() BEGIN
       SAVEPOINT s;
       INSERT INTO t1 VALUES (10);
       ROLLBACK TO SAVEPOINT s;
END|
--delimiter ;
BEGIN;
CALL p5();
COMMIT;
DROP TRIGGER i6_t1;

--connection node_2
delimiter |;
create trigger t1 before insert on t1 for each row
begin
    insert into t2 values (NULL);
end|
delimiter ;|

--connection node_1 
INSERT INTO t1 VALUES (201), (202), (203);

--connection node_1 
SELECT * FROM t1;
SELECT COUNT(*) FROM t2;

--connection node_2
SELECT * FROM t1;
SELECT COUNT(*) FROM t2;

--connection node_1
DEALLOCATE PREPARE call_p1;

--connection node_2
DROP TABLE t1, t2;
DROP PROCEDURE p1;
DROP PROCEDURE p2;
DROP PROCEDURE p3;
DROP PROCEDURE p4;
DROP PROCEDURE p5;
DROP FUNCTION f1;