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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3,t4;
--enable_warnings
######## Running DELETE tests for DECIMAL ########
# Create tables
CREATE TABLE t1(c1 DECIMAL(10,5) UNSIGNED NOT NULL, c2 DECIMAL(10,5) SIGNED NULL, c3 DECIMAL, c4 INT, UNIQUE INDEX idx(c1,c4));
# Inserting data into table t1
# Trailing zeroes are not stripped, D=5
INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2);
# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped;
INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3);
# c1, c2, c3 will be rounded automatically
INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4);
# Inserting maximum values
INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5);
# Test insert leading zero, +/- signs, overflow handling
INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7);
INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9);
# Inserting in scientific notations
INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10);
#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11);
--sorted_result
SELECT * FROM t1;
# Deletion starts here
# Delete by order by limit
DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;
# Delete using range values
DELETE FROM t1 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
DELETE FROM t1 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;
TRUNCATE t1;
INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9);
--sorted_result
SELECT * FROM t1;
SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--sorted_result
SELECT * FROM t1;
# Multi table delete
CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx2(c1,c3));
CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1,c3));
CREATE TABLE t4(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx4(c1,c3));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9);
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--sorted_result
SELECT * FROM t4;
DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888';
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
# Delete using various access methods
TRUNCATE t2;
TRUNCATE t3;
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
# Delete using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;
# Delete using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;
# Delete using eq_ref
DROP TABLE t2,t3;
CREATE TABLE t2(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT);
CREATE TABLE t3(c1 DECIMAL(10,5) NOT NULL, c2 DECIMAL, c3 INT, UNIQUE INDEX idx3(c1));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3);
# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--sorted_result
SELECT * FROM t4;
# Droping the tables
--disable_warnings
DROP TABLES IF EXISTS t1,t2,t3,t4;
--enable_warnings
######## Running DELETE tests for FLOAT ########
# Create tables
CREATE TABLE t1(c1 FLOAT(10,5) UNSIGNED NOT NULL, c2 FLOAT(10,5) SIGNED NULL, c3 FLOAT, c4 INT, UNIQUE INDEX idx(c1,c4));
# Inserting data into table t1
# Trailing zeroes are not stripped, D=5
INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2);
# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped;
INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3);
# c1, c2, c3 will be rounded automatically
INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4);
# Inserting maximum values
INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5);
# Test insert leading zero, +/- signs, overflow handling
INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7);
INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9);
# Inserting in scientific notations
INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10);
#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11);
--sorted_result
SELECT * FROM t1;
# Deletion starts here
# Delete by order by limit
DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;
# Delete using range values
DELETE FROM t1 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
DELETE FROM t1 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;
TRUNCATE t1;
INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9);
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
# Multi table delete
CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx2(c1,c3));
CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1,c3));
CREATE TABLE t4(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx4(c1,c3));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9);
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t4;
DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888';
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
# Delete using various access methods
TRUNCATE t2;
TRUNCATE t3;
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
# Delete using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;
# Delete using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;
# Delete using eq_ref
DROP TABLE t2,t3;
CREATE TABLE t2(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT);
CREATE TABLE t3(c1 FLOAT(10,5) NOT NULL, c2 FLOAT, c3 INT, UNIQUE INDEX idx3(c1));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3);
# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t4;
# Droping the tables
--disable_warnings
DROP TABLES IF EXISTS t1,t2,t3,t4;
--enable_warnings
######## Running DELETE tests for DOUBLE ########
# Create tables
CREATE TABLE t1(c1 DOUBLE(10,5) UNSIGNED NOT NULL, c2 DOUBLE(10,5) SIGNED NULL, c3 DOUBLE, c4 INT, UNIQUE INDEX idx(c1,c4));
# Inserting data into table t1
# Trailing zeroes are not stripped, D=5
INSERT INTO t1 VALUES('00100.05000','-00100.05000','00100119',1),('11111.00009','-9999.99999','9999999',2);
# DECIMAL := DECIMAL(10,0); Decimal values in c3 will be stripped;
INSERT IGNORE INTO t1 VALUES('1000000','10000000','1000000000.0001',3);
# c1, c2, c3 will be rounded automatically
INSERT INTO t1 values('100.000001','1000.999999','9999.999999',4);
# Inserting maximum values
INSERT INTO t1 VALUES('99999.99999','-99999.99999','9999999999',5);
# Test insert leading zero, +/- signs, overflow handling
INSERT INTO t1 VALUES ("0.0","0.0","0.0",6),("01.0","01.0","01.0",7);
INSERT IGNORE INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT IGNORE INTO t1 VALUES ("+111111111.11","+111111111.11","+111111111.11",9);
# Inserting in scientific notations
INSERT INTO t1 VALUES('1.0e+4','1.0e-5','1.0e+9',10);
#INSERT INTO t1 VALUES('0.9999999999e+4','-.999999999e+4,'0.9999999999e+10',11);
--sorted_result
SELECT * FROM t1;
# Deletion starts here
# Delete by order by limit
DELETE FROM t1 WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;
# Delete using range values
DELETE FROM t1 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
DELETE FROM t1 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
DELETE FROM t1 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;
TRUNCATE t1;
INSERT INTO t1 VALUES ('11111.11111','-11111.11111','1111111111',1),('22222.22222','-22222.22222','2222222222',2),('33333.33333','-33333.33333','3333333333',3),('44444.44444','-44444.44444','4444444444',4),('55555.55555','-55555.55555','5555555555',5),('66666.66666','-66666.66666','6666666666',6),('77777.77777','-77777.77777','7777777777',7),('88888.88888','-88888.88888','8888888888',8),('99999.99999','-99999.99999','9999999999',9);
--sorted_result
SELECT * FROM t1;
SELECT c1 FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
DELETE FROM t1 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--sorted_result
SELECT * FROM t1;
# Multi table delete
CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx2(c1,c3));
CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1,c3));
CREATE TABLE t4(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx4(c1,c3));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
INSERT INTO t4 VALUES ('77777.77777','7777777777',7),('88888.88888','8888888888',8),('99999.99999','9999999999',9);
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--sorted_result
SELECT * FROM t4;
DELETE t1,t2,t3,t4 FROM t1,t2,t3,t4 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888';
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
# Delete using various access methods
TRUNCATE t2;
TRUNCATE t3;
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('44444.44444','4444444444',4),('55555.55555','5555555555',5),('66666.66666','6666666666',6);
# Delete using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
DELETE FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;
# Delete using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
DELETE FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
DELETE FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;
# Delete using eq_ref
DROP TABLE t2,t3;
CREATE TABLE t2(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT);
CREATE TABLE t3(c1 DOUBLE(10,5) NOT NULL, c2 DOUBLE, c3 INT, UNIQUE INDEX idx3(c1));
INSERT INTO t2 VALUES ('11111.11111','1111111111',1),('22222.22222','2222222222',2),('33333.33333','3333333333',3);
INSERT INTO t3 VALUES ('11111.11111','4444444444',1),('55555.55555','5555555555',2),('66666.66666','6666666666',3);
# EXPLAIN SELECT * FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
DELETE t2,t3 FROM t2,t3 WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t2;
--sorted_result
SELECT * FROM t3;
--sorted_result
SELECT * FROM t4;
# Droping the tables
--disable_warnings
DROP TABLES IF EXISTS t1,t2,t3,t4;
--enable_warnings
|