summaryrefslogtreecommitdiff
path: root/mysql-test/suite/engines/iuds/t/update_decimal.test
blob: aa96665e82d20e6b6c9f8659eec1112af2e40364 (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3,t4;
--enable_warnings

######## Running UPDATE 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 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 INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT 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;

# UPDATE starts here

# Update order by limit
UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;

# Update with arithmetic operations 
UPDATE t1 SET c1=c2+c3 WHERE c3 < 10000;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4;
--sorted_result
SELECT * FROM t1;

# Update with NULL ( NULL to number & number to NULL)
UPDATE t1 SET c2=NULL WHERE c4=4;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL;
--sorted_result
SELECT * FROM t1;

# Update negative value to unsigned column
UPDATE t1 SET c1=-1.0e+2 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.0e+20 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;

# Update range values
UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;

# Update outside range would be clipped to closest endpoints
UPDATE t1 SET c1=99999.999999 WHERE c4=7;
--sorted_result
SELECT c1,c4 FROM t1;
UPDATE t1 SET c2=-9999.0099 WHERE c4=5;
--sorted_result
SELECT c2,c4 FROM t1;

# Update ignore on bad null error
SELECT c1 FROM t1 WHERE c1>1000;
SET SQL_MODE=STRICT_ALL_TABLES;
--error ER_BAD_NULL_ERROR
UPDATE t1 SET c1=NULL WHERE c1>1000;
UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000;
--sorted_result
SELECT c1 from t1 WHERE c1>1000;
SET SQL_MODE=DEFAULT;

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;
UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--sorted_result
SELECT * FROM t1;

# Multi table update
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;
UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888' ;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;

# Update 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);

# Update using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;

# Update using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;

# Update 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;
UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;

#Updating with invalid values
UPDATE t1 SET c3='asdf' WHERE c1='11111.11111';
--sorted_result
SELECT c3 FROM t1;
UPDATE t1 SET c2="1 e 1" WHERE c4=2;
--sorted_result
SELECT c2 FROM t1;

#Duplicate keys
--error ER_DUP_ENTRY
UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7;

--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 UPDATE 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 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 INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT 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;

# UPDATE starts here

# Update order by limit
UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;

# Update with arithmetic operations 
UPDATE t1 SET c1=c2+c3 WHERE c3 < 10000;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4;
--sorted_result
SELECT * FROM t1;

# Update with NULL ( NULL to number & number to NULL)
UPDATE t1 SET c2=NULL WHERE c4=4;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL;
--sorted_result
SELECT * FROM t1;

# Update negative value to unsigned column
UPDATE t1 SET c1=-1.0e+2 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.0e+20 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;

# Update range values
UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;

# Update outside range would be clipped to closest endpoints
UPDATE t1 SET c1=99999.999999 WHERE c4=7;
--sorted_result
SELECT c1,c4 FROM t1;
UPDATE t1 SET c2=-9999.0099 WHERE c4=5;
--sorted_result
SELECT c2,c4 FROM t1;

# Update ignore on bad null error
SELECT c1 FROM t1 WHERE c1>1000;
SET SQL_MODE=STRICT_ALL_TABLES;
--error ER_BAD_NULL_ERROR
UPDATE t1 SET c1=NULL WHERE c1>1000;
UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000;
--sorted_result
SELECT c1 from t1 WHERE c1>1000;
SET SQL_MODE=DEFAULT;

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;
UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT * FROM t1;

# Multi table update
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;
UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 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;

# Update 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);

# Update using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;

# Update using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;

# Update 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;
UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;

#Updating with invalid values
UPDATE t1 SET c3='asdf' WHERE c1='11111.11111';
--sorted_result
SELECT c3 FROM t1;
UPDATE t1 SET c2="1 e 1" WHERE c4=2;
--replace_result 88888.89063 88888.89062
--sorted_result
SELECT c2 FROM t1;

#Duplicate keys
--replace_result 88888.89063 88888.89062
--error ER_DUP_ENTRY
UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7;
--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 UPDATE 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 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 INTO t1 VALUES ("-.1","-.1","-.1",8);
INSERT 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;

# UPDATE starts here

# Update order by limit
UPDATE t1 SET c1='10001.00001' WHERE c2 > 100 ORDER BY c2 LIMIT 1;
--sorted_result
SELECT c1,c2 FROM t1;

# Update with arithmetic operations 
UPDATE t1 SET c1=c2+c3 WHERE c3 < 10000;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=c2+100 WHERE c1 >=100 ORDER BY c1 LIMIT 4;
--sorted_result
SELECT * FROM t1;

# Update with NULL ( NULL to number & number to NULL)
UPDATE t1 SET c2=NULL WHERE c4=4;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c2=1.0e+5 WHERE c2=NULL;
--sorted_result
SELECT * FROM t1;

# Update negative value to unsigned column
UPDATE t1 SET c1=-1.0e+2 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.0e+20 WHERE c4=2;
SHOW WARNINGS;
--sorted_result
SELECT * FROM t1;

# Update range values
UPDATE t1 SET c1=0.9999999999e+5 WHERE c3=1 AND c4=7;
--sorted_result
SELECT * FROM t1;
UPDATE t1 SET c1=1.2e+2,c2=c4+c2 WHERE c3=9999999999 OR c2=1.0e-5;
--sorted_result
SELECT * FROM t1 WHERE c1=1.2e+2;
UPDATE t1 SET c3=1234567890 WHERE c4 IN (4,5,6);
--sorted_result
SELECT * FROM t1;

# Update outside range would be clipped to closest endpoints
UPDATE t1 SET c1=99999.999999 WHERE c4=7;
--sorted_result
SELECT c1,c4 FROM t1;
UPDATE t1 SET c2=-9999.0099 WHERE c4=5;
--sorted_result
SELECT c2,c4 FROM t1;

# Update ignore on bad null error
SELECT c1 FROM t1 WHERE c1>1000;
SET SQL_MODE=STRICT_ALL_TABLES;
--error ER_BAD_NULL_ERROR
UPDATE t1 SET c1=NULL WHERE c1>1000;
UPDATE IGNORE t1 SET c1=NULL WHERE c1>1000;
--sorted_result
SELECT c1 from t1 WHERE c1>1000;
SET SQL_MODE=DEFAULT;

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;
UPDATE t1 SET c1=c1-100, c2=c1+c2 WHERE c1>='22222.22222' AND c1<='55555.55555' ORDER BY c1;
--sorted_result
SELECT * FROM t1;

# Multi table update
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;
UPDATE t1,t2,t3,t4 SET t2.c1=t2.c1+t3.c1, t3.c2=t3.c2-t2.c1, t4.c1=t1.c1*t1.c3 WHERE t1.c2 >'1111111111' AND t4.c2 < '8888888888' ;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM t1;

# Update 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);

# Update using Const
# EXPLAIN SELECT * FROM t2 WHERE t2.c1='22222.22222' AND t2.c3=2;
UPDATE t2 SET t2.c1='44444.44444', t2.c3=4 WHERE t2.c1='22222.22222' AND t2.c3=2;
--sorted_result
SELECT * FROM t2;

# Update using range
# EXPLAIN SELECT * FROM t2 WHERE c1 BETWEEN '11111' AND '44444';
update t2 set t2.c1='99999.99999' where c1 BETWEEN '11111' AND '44444';
--sorted_result
SELECT * FROM t2;
# EXPLAIN SELECT * FROM t2 WHERE c1 IN ('44444.44444','99999.99999');
UPDATE t2 SET c1=c1-1,c2=c2-1 WHERE c1 IN ('44444.44444','99999.99999');
--sorted_result
SELECT * FROM t2;

# Update 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;
UPDATE t2,t3 SET t3.c1='22222.22222' WHERE t2.c1=t3.c1 AND t2.c3=t3.c3;

#Updating with invalid values
UPDATE t1 SET c3='asdf' WHERE c1='11111.11111';
--sorted_result
SELECT c3 FROM t1;
UPDATE t1 SET c2="1 e 1" WHERE c4=2;
--sorted_result
SELECT c2 FROM t1;

#Duplicate keys
--error ER_DUP_ENTRY
UPDATE t4 SET c1=88888.88888,c3=8 WHERE c3=7;

--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