~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/suite/rpl/t/rpl_user_variables.test

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###################################
 
2
#
 
3
# Test of replicating user variables
 
4
#
 
5
###################################
 
6
 
 
7
-- source include/master-slave.inc
 
8
# Disable PS as the log positions differs
 
9
--disable_ps_protocol
 
10
 
 
11
 
 
12
# Clean up old slave's binlogs.
 
13
# The slave is started with --log-slave-updates
 
14
# and this test does SHOW BINLOG EVENTS on the slave's
 
15
# binlog. But previous tests can influence the current test's
 
16
# binlog (e.g. a temporary table in the previous test has not
 
17
# been explicitly deleted, or it has but the slave hasn't had
 
18
# enough time to catch it before STOP SLAVE, 
 
19
# and at the beginning of the current
 
20
# test the slave immediately writes DROP TEMPORARY TABLE this_old_table).
 
21
# We wait for the slave to have written all he wants to the binlog
 
22
# (otherwise RESET MASTER may come too early).
 
23
save_master_pos;
 
24
connection slave;
 
25
sync_with_master;
 
26
reset master;
 
27
connection master;
 
28
 
 
29
create table t1(n char(30));
 
30
set @i1:=12345678901234, @i2:=-12345678901234, @i3:=0, @i4:=-1;
 
31
set @s1:='This is a test', @r1:=12.5, @r2:=-12.5;
 
32
set @n1:=null;
 
33
set @s2:='', @s3:='abc\'def', @s4:= 'abc\\def', @s5:= 'abc''def';
 
34
insert into t1 values (@i1), (@i2), (@i3), (@i4);
 
35
insert into t1 values (@r1), (@r2);
 
36
insert into t1 values (@s1), (@s2), (@s3), (@s4), (@s5);
 
37
insert into t1 values (@n1);
 
38
insert into t1 values (@n2); # not explicitely set before
 
39
insert into t1 values (@a:=0), (@a:=@a+1), (@a:=@a+1);
 
40
insert into t1 values (@a+(@b:=@a+1));
 
41
set @q:='abc';
 
42
insert t1 values (@q), (@q:=concat(@q, 'n1')), (@q:=concat(@q, 'n2'));
 
43
set @a:=5;
 
44
insert into t1 values (@a),(@a);
 
45
# To flush the pending event, we add the following statement. RBR can
 
46
# concatenate the result of several statements, which SBR cannot.
 
47
select * from t1 where n = '<nonexistant>';
 
48
connection master1; # see if variable is reset in binlog when thread changes
 
49
insert into t1 values (@a),(@a),(@a*5);
 
50
SELECT * FROM t1 ORDER BY n;
 
51
sync_slave_with_master;
 
52
SELECT * FROM t1 ORDER BY n;
 
53
connection master;
 
54
insert into t1 select * FROM (select @var1 union  select @var2) AS t2;
 
55
drop table t1;
 
56
--echo End of 4.1 tests.
 
57
 
 
58
# BUG#20141
 
59
# The following tests ensure that if user-defined variables are used in SF/Triggers 
 
60
# that they are replicated correctly. These tests should be run in both SBR and RBR 
 
61
# modes.
 
62
 
 
63
# This test uses a procedure that inserts data values based on the value of a 
 
64
# user-defined variable. It also has a trigger that inserts data based on the 
 
65
# same variable. Successful test runs show that the @var is replicated 
 
66
# properly and that the procedure and trigger insert the correct data on the 
 
67
# slave.
 
68
#
 
69
# The test of stored procedure was included for completeness. Replication of stored 
 
70
# procedures was not directly affected by BUG#20141.
 
71
#
 
72
# This test was constructed for BUG#20141
 
73
 
 
74
--disable_warnings
 
75
DROP TABLE IF EXISTS t20;
 
76
DROP TABLE IF EXISTS t21;
 
77
DROP PROCEDURE IF EXISTS test.insert;
 
78
--enable_warnings
 
79
 
 
80
CREATE TABLE t20 (a VARCHAR(20));
 
81
CREATE TABLE t21 (a VARCHAR(20));
 
82
DELIMITER |;
 
83
 
 
84
# Create a procedure that uses the @var for flow control
 
85
 
 
86
CREATE PROCEDURE test.insert()
 
87
BEGIN
 
88
  IF (@VAR)
 
89
  THEN
 
90
      INSERT INTO test.t20 VALUES ('SP_TRUE');
 
91
  ELSE
 
92
      INSERT INTO test.t20 VALUES ('SP_FALSE');
 
93
  END IF;
 
94
END|
 
95
 
 
96
# Create a trigger that uses the @var for flow control
 
97
 
 
98
CREATE TRIGGER test.insert_bi BEFORE INSERT
 
99
    ON test.t20 FOR EACH ROW
 
100
    BEGIN
 
101
      IF (@VAR)
 
102
      THEN
 
103
        INSERT INTO test.t21 VALUES ('TRIG_TRUE');
 
104
      ELSE
 
105
        INSERT INTO test.t21 VALUES ('TRIG_FALSE');
 
106
      END IF;
 
107
    END|
 
108
DELIMITER ;|
 
109
 
 
110
sync_slave_with_master;
 
111
connection master;
 
112
 
 
113
# Set @var and call the procedure, repeat with different values
 
114
 
 
115
SET @VAR=0;
 
116
CALL test.insert();
 
117
SET @VAR=1;
 
118
CALL test.insert();
 
119
 
 
120
--echo On master: Check the tables for correct data
 
121
 
 
122
SELECT * FROM t20;
 
123
SELECT * FROM t21;
 
124
 
 
125
sync_slave_with_master;
 
126
 
 
127
--echo On slave: Check the tables for correct data and it matches master
 
128
 
 
129
SELECT * FROM t20;
 
130
SELECT * FROM t21;
 
131
connection master;
 
132
 
 
133
# Cleanup
 
134
 
 
135
DROP TABLE t20;
 
136
DROP TABLE t21;
 
137
DROP PROCEDURE test.insert;
 
138
 
 
139
# This test uses a stored function that uses user-defined variables to return data 
 
140
# This test was constructed for BUG#20141
 
141
 
 
142
--disable_warnings
 
143
DROP TABLE IF EXISTS t1;
 
144
DROP FUNCTION IF EXISTS test.square;
 
145
--enable_warnings
 
146
 
 
147
CREATE TABLE t1 (i INT);
 
148
 
 
149
# Create function that returns a value from @var. In this case, the square function
 
150
 
 
151
CREATE FUNCTION test.square() RETURNS INTEGER DETERMINISTIC RETURN 
 
152
(@var * @var);
 
153
 
 
154
# Set the @var to different values and insert them into a table
 
155
 
 
156
SET @var = 1;
 
157
INSERT INTO t1 VALUES (square());
 
158
SET @var = 2;
 
159
INSERT INTO t1 VALUES (square());
 
160
SET @var = 3;
 
161
INSERT INTO t1 VALUES (square());
 
162
SET @var = 4;
 
163
INSERT INTO t1 VALUES (square());
 
164
SET @var = 5;
 
165
INSERT INTO t1 VALUES (square());
 
166
 
 
167
--echo On master: Retrieve the values from the table
 
168
 
 
169
SELECT * FROM t1;
 
170
 
 
171
sync_slave_with_master;
 
172
 
 
173
--echo On slave: Retrieve the values from the table and verify they are the same as on master
 
174
 
 
175
SELECT * FROM t1;
 
176
 
 
177
connection master;
 
178
 
 
179
# Cleanup
 
180
 
 
181
DROP TABLE t1;
 
182
DROP FUNCTION test.square;
 
183
 
 
184
# This test uses stored functions that uses user-defined variables to return data 
 
185
# based on the use of @vars inside a function body.
 
186
# This test was constructed for BUG#14914
 
187
 
 
188
--disable_warnings
 
189
DROP TABLE IF EXISTS t1;
 
190
DROP FUNCTION IF EXISTS f1;
 
191
DROP FUNCTION IF EXISTS f2;
 
192
--enable_warnings
 
193
 
 
194
CREATE TABLE t1(a int);
 
195
DELIMITER |;
 
196
 
 
197
# Create a function that simply returns the value of an @var.
 
198
# Create a function that uses an @var for flow control, creates and uses another 
 
199
# @var and sets its value to a value based on another @var.
 
200
 
 
201
CREATE FUNCTION f1() returns int deterministic BEGIN
 
202
  return @a;
 
203
END |
 
204
 
 
205
CREATE FUNCTION f2() returns int deterministic BEGIN
 
206
  IF (@b > 0) then
 
207
    SET @c = (@a + @b);
 
208
  else
 
209
    SET @c = (@a - 1);
 
210
  END if;
 
211
  return @c;
 
212
END |
 
213
DELIMITER ;|
 
214
 
 
215
sync_slave_with_master;
 
216
connection master;
 
217
 
 
218
# Set an @var to a value and insert data into a table using the first function.
 
219
# Set two more @vars to some values and insert data into a table using the second function.
 
220
 
 
221
SET @a=500;
 
222
INSERT INTO t1 values(f1());
 
223
SET @b = 125;
 
224
SET @c = 1;
 
225
INSERT INTO t1 values(f2());
 
226
 
 
227
--echo On master: Retrieve the values from the table
 
228
 
 
229
sync_slave_with_master;
 
230
connection master;
 
231
 
 
232
SELECT * from t1;
 
233
 
 
234
connection slave;
 
235
 
 
236
--echo On slave: Check the tables for correct data and it matches master
 
237
 
 
238
SELECT * from t1;
 
239
 
 
240
connection master;
 
241
 
 
242
# Cleanup
 
243
 
 
244
DROP TABLE t1;
 
245
DROP FUNCTION f1;
 
246
DROP FUNCTION f2;
 
247
 
 
248
# This test uses a function that changes a user-defined variable in its body. This test 
 
249
# will ensure the @vars are replicated when needed and not interrupt the normal execution 
 
250
# of the function on the slave. This also applies to procedures and triggers.
 
251
 
 
252
# This test was constructed for BUG#25167
 
253
 
 
254
--disable_warnings
 
255
DROP TABLE IF EXISTS t1;
 
256
DROP TABLE IF EXISTS t2;
 
257
--enable_warnings
 
258
CREATE TABLE t1 (i int);
 
259
CREATE TABLE t2 (k int);
 
260
DELIMITER |;
 
261
 
 
262
# Create a trigger that inserts data into another table, changes the @var then inserts 
 
263
# another row with the modified value.
 
264
 
 
265
CREATE trigger t1_bi before INSERT on t1 for each row BEGIN
 
266
  INSERT INTO t2 values (@a);
 
267
  SET @a:=42;
 
268
  INSERT INTO t2 values (@a);
 
269
END |
 
270
DELIMITER ;|
 
271
 
 
272
sync_slave_with_master;
 
273
connection master;
 
274
 
 
275
# Set the @var to a value then insert data into first table.
 
276
 
 
277
SET @a:=100;
 
278
INSERT INTO t1 values (5);
 
279
 
 
280
--echo On master: Check to see that data was inserted correctly in both tables
 
281
 
 
282
SELECT * from t1;
 
283
SELECT * from t2;
 
284
 
 
285
sync_slave_with_master;
 
286
 
 
287
--echo On slave: Check the tables for correct data and it matches master
 
288
 
 
289
SELECT * from t1;
 
290
SELECT * from t2;
 
291
 
 
292
connection master;
 
293
drop table t1, t2;
 
294
 
 
295
#
 
296
# Bug #12826: Possible to get inconsistent slave using SQL syntax Prepared Statements
 
297
#
 
298
connection master;
 
299
create table t1(a int, b int);
 
300
prepare s1 from 'insert into t1 values (@x:=@x+1, ?)';
 
301
set @x=1; execute s1 using @x;
 
302
select * from t1;
 
303
sync_slave_with_master;
 
304
connection slave;
 
305
select * from t1;
 
306
connection master;
 
307
drop table t1;
 
308
 
 
309
#
 
310
# Bug#33851: Passing UNSIGNED param to EXECUTE returns ERROR 1210
 
311
#
 
312
 
 
313
connection master;
 
314
create table t1(a int);
 
315
insert into t1 values (1),(2);
 
316
prepare s1 from 'insert into t1 select a from t1 limit ?';
 
317
set @x='1.1';
 
318
--disable_warnings
 
319
execute s1 using @x;
 
320
--enable_warnings
 
321
select * from t1;
 
322
sync_slave_with_master;
 
323
connection slave;
 
324
select * from t1;
 
325
connection master;
 
326
drop table t1;
 
327
 
 
328
--echo End of 5.0 tests.
 
329
 
 
330
# This test uses a stored function that uses user-defined variables to return data 
 
331
# The test ensures the value of the user-defined variable is replicated correctly 
 
332
# and in the correct order of assignment.
 
333
 
 
334
# This test was constructed for BUG#20141
 
335
 
 
336
--disable_warnings
 
337
DROP FUNCTION IF EXISTS f1;
 
338
DROP FUNCTION IF EXISTS f2;
 
339
--enable_warnings
 
340
 
 
341
CREATE TABLE t1 (i INT);
 
342
 
 
343
# Create two functions. One simply returns the user-defined variable. The other 
 
344
# returns a value based on the user-defined variable.
 
345
 
 
346
CREATE FUNCTION f1() RETURNS INT RETURN @a; DELIMITER |; CREATE 
 
347
FUNCTION f2() RETURNS INT BEGIN
 
348
  INSERT INTO t1 VALUES (10 + @a);
 
349
  RETURN 0;
 
350
END|
 
351
DELIMITER ;|
 
352
 
 
353
sync_slave_with_master;
 
354
connection master;
 
355
 
 
356
# Set the variable and execute the functions.
 
357
 
 
358
SET @a:=123;
 
359
SELECT f1(), f2();
 
360
 
 
361
--echo On master: Check to see that data was inserted correctly
 
362
 
 
363
INSERT INTO t1 VALUES(f1());
 
364
SELECT * FROM t1;
 
365
 
 
366
sync_slave_with_master;
 
367
 
 
368
--echo On slave: Check the table for correct data and it matches master
 
369
 
 
370
SELECT * FROM t1;
 
371
 
 
372
connection master;
 
373
 
 
374
# Cleanup
 
375
 
 
376
DROP FUNCTION f1;
 
377
DROP FUNCTION f2;
 
378
DROP TABLE t1;
 
379
 
 
380
sync_slave_with_master;
 
381
stop slave;