summaryrefslogtreecommitdiff
path: root/mysql-test/extra/rpl_tests/rpl_not_null.test
blob: 86f49d1665c61162010de69d763acec87124b832 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#################################################################################
# This test checks if the replication between "null" fields to either "null"
# fields or "not null" fields works properly. In the first case, the execution
# should work fine. In the second case, it may fail according to the sql_mode
# being used.
#
# The test is devided in three main parts:
#
# 1 - NULL --> NULL (no failures)
# 2 - NULL --> NOT NULL ( sql-mode  = STRICT and failures)
# 3 - NULL --> NOT NULL ( sql-mode != STRICT and no failures)
#
#################################################################################
connection master;

SET SQL_LOG_BIN= 0;
eval CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
`c` INT DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t3(`a` INT, `b` DATE DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t4(`a` INT, `b` DATE DEFAULT NULL,
`c` INT DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
SET SQL_LOG_BIN= 1;

connection slave;

eval CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
`c` INT DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t3(`a` INT, `b` DATE DEFAULT '0000-00-00',
`c` INT DEFAULT 500, 
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

eval CREATE TABLE t4(`a` INT, `b` DATE DEFAULT '0000-00-00',
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

--echo ************* EXECUTION WITH INSERTS *************
connection master;
INSERT INTO t1(a,b,c) VALUES (1, null, 1);
INSERT INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
INSERT INTO t1(a,b) VALUES (3, null);
INSERT INTO t1(a,c) VALUES (4, 4);
INSERT INTO t1(a) VALUES (5);

INSERT INTO t2(a,b) VALUES (1, null);
INSERT INTO t2(a,b) VALUES (2,'1111-11-11');
INSERT INTO t2(a) VALUES (3);

INSERT INTO t3(a,b) VALUES (1, null);
INSERT INTO t3(a,b) VALUES (2,'1111-11-11');
INSERT INTO t3(a) VALUES (3);

INSERT INTO t4(a,b,c) VALUES (1, null, 1);
INSERT INTO t4(a,b,c) VALUES (2,'1111-11-11', 2);
INSERT INTO t4(a,b) VALUES (3, null);
INSERT INTO t4(a,c) VALUES (4, 4);
INSERT INTO t4(a) VALUES (5);

--echo ************* SHOWING THE RESULT SETS WITH INSERTS *************
sync_slave_with_master;

--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
let $diff_tables= master:t1, slave:t1;
source include/diff_tables.inc;
 
let $diff_tables= master:t2, slave:t2;
source include/diff_tables.inc;

--echo TABLES t2 and t3 must be different.
connection master;
SELECT * FROM t3 ORDER BY a;
connection slave;
SELECT * FROM t3 ORDER BY a;
connection master;
SELECT * FROM t4 ORDER BY a;
connection slave;
SELECT * FROM t4 ORDER BY a;

--echo ************* EXECUTION WITH UPDATES and REPLACES *************
connection master;
DELETE FROM t1;
INSERT INTO t1(a,b,c) VALUES (1,'1111-11-11', 1);
REPLACE INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
UPDATE t1 set b= NULL, c= 300 where a= 1;
REPLACE INTO t1(a,b,c) VALUES (2, NULL, 300);

--echo ************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
sync_slave_with_master;

--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
let $diff_tables= master:t1, slave:t1;
source include/diff_tables.inc;

--echo ************* CLEANING *************
connection master;

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;

sync_slave_with_master;
  
connection master;

SET SQL_LOG_BIN= 0;
eval CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT NULL, `c` BIT DEFAULT NULL, 
PRIMARY KEY (`a`)) ENGINE= $engine;
SET SQL_LOG_BIN= 1;

connection slave;

eval CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT b'01', `c` BIT DEFAULT NULL,
PRIMARY KEY (`a`)) ENGINE= $engine;

--echo ************* EXECUTION WITH INSERTS *************
connection master;
INSERT INTO t1(a,b,c) VALUES (1, null, b'01');
INSERT INTO t1(a,b,c) VALUES (2,b'00', b'01');
INSERT INTO t1(a,b) VALUES (3, null);
INSERT INTO t1(a,c) VALUES (4, b'01');
INSERT INTO t1(a) VALUES (5);

--echo ************* SHOWING THE RESULT SETS WITH INSERTS *************
--echo TABLES t1 and t2 must be different.
sync_slave_with_master;
connection master;
SELECT a,b+0,c+0 FROM t1 ORDER BY a;
connection slave;
SELECT a,b+0,c+0 FROM t1 ORDER BY a;

--echo ************* EXECUTION WITH UPDATES and REPLACES *************
connection master;
DELETE FROM t1;
INSERT INTO t1(a,b,c) VALUES (1,b'00', b'01');
REPLACE INTO t1(a,b,c) VALUES (2,b'00',b'01');
UPDATE t1 set b= NULL, c= b'00' where a= 1;
REPLACE INTO t1(a,b,c) VALUES (2, NULL, b'00');

--echo ************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
sync_slave_with_master;
let $diff_tables= master:t1, slave:t1;
source include/diff_tables.inc;
 
connection master;

DROP TABLE t1;

sync_slave_with_master;
  
--echo ################################################################################
--echo #                       NULL ---> NOT NULL (STRICT MODE)
--echo #                    UNCOMMENT THIS AFTER FIXING BUG#43992
--echo ################################################################################
#connection slave;
#SET GLOBAL sql_mode="TRADITIONAL";
#
#STOP SLAVE;
#--source include/wait_for_slave_to_stop.inc
#START SLAVE;
#--source include/wait_for_slave_to_start.inc
#
#let $y=0;
#while (`select $y < 6`)
#{
#  connection master;
#
#  SET SQL_LOG_BIN= 0;
#  eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  SET SQL_LOG_BIN= 1;
#  
#  connection slave;
#  
#  eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
#  `c` INT NOT NULL,
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
#  `c` INT, 
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
#  `c` INT DEFAULT 500, 
#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
#  
#  if (`select $y=0`)
#  {
#    --echo ************* EXECUTION WITH INSERTS *************
#    connection master;
#    INSERT INTO t1(a) VALUES (1);
#  }
#  
#  if (`select $y=1`)
#  {
#    --echo ************* EXECUTION WITH INSERTS *************
#    connection master;
#    INSERT INTO t1(a, b) VALUES (1, NULL);
#  }
#  
#  if (`select $y=2`)
#  {
#    --echo ************* EXECUTION WITH UPDATES *************
#    connection master;
#    INSERT INTO t3(a, b) VALUES (1, 1);
#    INSERT INTO t3(a, b) VALUES (2, 1);
#    UPDATE t3 SET b = NULL where a= 1;
#  }
#  
#  if (`select $y=3`)
#  {
#    --echo ************* EXECUTION WITH INSERTS/REPLACES *************
#    connection master;
#    REPLACE INTO t3(a, b) VALUES (1, null);
#  }
#   
#  if (`select $y=4`)
#  {
#    --echo ************* EXECUTION WITH UPDATES/REPLACES *************
#    connection master;
#    INSERT INTO t3(a, b) VALUES (1, 1);
#    REPLACE INTO t3(a, b) VALUES (1, null);
#  }
#   
#  if (`select $y=5`)
#  {
#    --echo ************* EXECUTION WITH MULTI-ROW INSERTS *************
#    connection master;
#
#    SET SQL_LOG_BIN= 0;
#    INSERT INTO t2(a, b) VALUES (1, 1);
#    INSERT INTO t2(a, b) VALUES (2, 1);
#    INSERT INTO t2(a, b) VALUES (3, null);
#    INSERT INTO t2(a, b) VALUES (4, 1);
#    INSERT INTO t2(a, b) VALUES (5, 1);
#    SET SQL_LOG_BIN= 1;
#
#    INSERT INTO t2 SELECT a + 10, b from t2;
#    --echo The statement below is just executed to stop processing
#    INSERT INTO t1(a) VALUES (1);
#  }
#  
#  --echo ************* SHOWING THE RESULT SETS *************
#  connection slave;
#  --source include/wait_for_slave_sql_to_stop.inc
#  connection master;
#  SELECT * FROM t1 ORDER BY a;
#  connection slave;
#  SELECT * FROM t1 ORDER BY a;
#  connection master;
#  SELECT * FROM t2 ORDER BY a;
#  connection slave;
#  SELECT * FROM t2 ORDER BY a;
#  connection master;
#  SELECT * FROM t3 ORDER BY a;
#  connection slave;
#  SELECT * FROM t3 ORDER BY a;
#  --source include/rpl_reset.inc
#  
#  connection master;
#  
#  DROP TABLE t1;
#  DROP TABLE t2;
#  DROP TABLE t3;
#  
#  sync_slave_with_master;
#
#  inc $y;
#}
#connection slave;
#SET GLOBAL sql_mode="";
#
#STOP SLAVE;
#source include/wait_for_slave_to_stop.inc;
#START SLAVE;
#--source include/wait_for_slave_to_start.inc

--echo ################################################################################
--echo #                       NULL ---> NOT NULL (NON-STRICT MODE)
--echo ################################################################################
connection master;

SET SQL_LOG_BIN= 0;
eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
SET SQL_LOG_BIN= 1;

connection slave;

eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
`c` INT NOT NULL,
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
`c` INT, 
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
`c` INT DEFAULT 500, 
PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;

--echo ************* EXECUTION WITH INSERTS *************
connection master;
INSERT INTO t1(a) VALUES (1);
INSERT INTO t1(a, b) VALUES (2, NULL);
INSERT INTO t1(a, b) VALUES (3, 1);

INSERT INTO t2(a) VALUES (1);
INSERT INTO t2(a, b) VALUES (2, NULL);
INSERT INTO t2(a, b) VALUES (3, 1);

INSERT INTO t3(a) VALUES (1);
INSERT INTO t3(a, b) VALUES (2, NULL);
INSERT INTO t3(a, b) VALUES (3, 1);
INSERT INTO t3(a, b) VALUES (4, 1);
REPLACE INTO t3(a, b) VALUES (5, null);

REPLACE INTO t3(a, b) VALUES (3, null);
UPDATE t3 SET b = NULL where a = 4;

--echo ************* SHOWING THE RESULT SETS *************
connection master;
sync_slave_with_master;

connection master;
SELECT * FROM t1 ORDER BY a;
connection slave;
SELECT * FROM t1 ORDER BY a;
connection master;
SELECT * FROM t2 ORDER BY a;
connection slave;
SELECT * FROM t2 ORDER BY a;
connection master;
SELECT * FROM t3 ORDER BY a;
connection slave;
SELECT * FROM t3 ORDER BY a;

connection master;

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;

sync_slave_with_master;