1 # inc/partition_auto_increment.inc
4 # used variables: $engine
8 DROP
TABLE IF EXISTS t1;
11 -- echo #
test without partitioning
for reference
12 eval CREATE
TABLE t1 (
13 c1 INT NOT NULL AUTO_INCREMENT,
17 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
19 INSERT INTO t1 VALUES (2);
20 INSERT INTO t1 VALUES (4);
21 INSERT INTO t1 VALUES (NULL);
22 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
24 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
26 INSERT INTO t1 VALUES (0);
27 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
28 INSERT INTO t1 VALUES (5), (16);
31 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
32 echo # mysql_errno: $mysql_errno;
34 INSERT INTO t1 VALUES (17);
35 INSERT INTO t1 VALUES (19), (NULL);
36 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
37 INSERT INTO t1 VALUES (NULL), (10), (NULL);
40 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
42 INSERT INTO t1 VALUES (NULL);
44 INSERT INTO t1 VALUES (NULL);
46 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
47 INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
50 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
51 echo # mysql_errno: $mysql_errno;
53 INSERT INTO t1 VALUES (NULL);
56 # InnoDB Does not handle this correctly, see bug#14793, bug#21641
57 UPDATE t1 SET c1 = 50 WHERE c1 = 17;
58 UPDATE t1 SET c1 = 51 WHERE c1 = 19;
60 UPDATE t1 SET c1 = 40 WHERE c1 = 50;
61 UPDATE t1 SET c1 = -1 WHERE c1 = 40;
62 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=
'test'
64 UPDATE t1 SET c1 = NULL WHERE c1 = 4;
65 INSERT INTO t1 VALUES (NULL);
66 INSERT INTO t1 VALUES (NULL);
68 SELECT * FROM t1
ORDER BY c1;
70 eval CREATE
TABLE t1 (
71 c1 INT NOT NULL AUTO_INCREMENT,
77 INSERT INTO t1 VALUES (4);
80 INSERT INTO t1 VALUES (NULL);
87 INSERT INTO t1 VALUES (NULL);
89 INSERT INTO t1 VALUES (-1);
92 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
94 INSERT INTO t1 VALUES (NULL);
95 INSERT INTO t1 VALUES (NULL);
97 SELECT * FROM t1
ORDER BY c1;
102 INSERT INTO t1 VALUES (NULL);
103 SHOW CREATE
TABLE t1;
104 SELECT * FROM t1
ORDER BY c1;
105 INSERT INTO t1 VALUES (100);
106 INSERT INTO t1 VALUES (NULL);
109 DELETE FROM t1 WHERE c1 >= 100;
111 # InnoDB does reset auto_increment on OPTIMIZE, Bug#18274
112 # Archive does reset auto_increment on OPTIMIZE, Bug#40216
114 SHOW CREATE
TABLE t1;
120 (a INT NULL AUTO_INCREMENT,
123 SET LAST_INSERT_ID = 999;
125 INSERT INTO t1 SET a = 1 ON DUPLICATE
KEY UPDATE a = NULL;
126 SELECT LAST_INSERT_ID();
128 INSERT INTO t1 SET a = 1 ON DUPLICATE
KEY UPDATE a = NULL;
129 SELECT LAST_INSERT_ID();
131 UPDATE t1 SET a = 1 WHERE a IS NULL;
132 SELECT LAST_INSERT_ID();
134 UPDATE t1 SET a = NULL WHERE a = 1;
135 SELECT LAST_INSERT_ID();
141 -- echo
# Simple test with NULL
142 eval CREATE
TABLE t1 (
143 c1 INT NOT NULL AUTO_INCREMENT,
146 PARTITION BY
HASH(c1)
148 INSERT INTO t1 VALUES (NULL);
149 SHOW CREATE
TABLE t1;
153 -- echo
# Test with sql_mode and first insert as 0
154 eval CREATE
TABLE t1 (
156 c2 INT NOT NULL AUTO_INCREMENT,
159 PARTITION BY
HASH(c2)
161 INSERT INTO t1 VALUES (1, NULL);
162 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
163 INSERT INTO t1 VALUES (1, 1), (99, 99);
166 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
167 echo # mysql_errno: $mysql_errno;
169 INSERT INTO t1 VALUES (1, NULL);
170 let $old_sql_mode = `select @@session.sql_mode`;
171 SET @@session.sql_mode =
'NO_AUTO_VALUE_ON_ZERO';
172 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
173 INSERT INTO t1 VALUES (1, 0);
176 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
178 SELECT * FROM t1
ORDER BY c1, c2;
180 eval CREATE
TABLE t1 (
182 c2 INT NOT NULL AUTO_INCREMENT,
185 PARTITION BY
HASH(c2)
187 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
188 INSERT INTO t1 VALUES (1, 0);
191 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
193 INSERT INTO t1 VALUES (1, 1), (1, NULL);
194 INSERT INTO t1 VALUES (2, NULL), (4, 7);
195 INSERT INTO t1 VALUES (1, NULL);
196 SELECT * FROM t1
ORDER BY c1, c2;
197 eval SET @@session.sql_mode =
'$old_sql_mode';
201 -- echo # Simple
test with NULL, 0 and
explicit values
both incr. and desc.
202 eval CREATE
TABLE t1 (
203 c1 INT NOT NULL AUTO_INCREMENT,
206 PARTITION BY
HASH(c1)
208 INSERT INTO t1 VALUES (2), (4), (NULL);
209 INSERT INTO t1 VALUES (0);
210 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
211 INSERT INTO t1 VALUES (5), (16);
214 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
215 echo # mysql_errno: $mysql_errno;
217 INSERT INTO t1 VALUES (17), (19), (NULL);
218 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
219 INSERT INTO t1 VALUES (NULL), (10), (NULL);
222 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
224 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
225 INSERT INTO t1 VALUES (NULL), (9);
228 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
230 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
231 INSERT INTO t1 VALUES (59), (55);
234 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
236 INSERT INTO t1 VALUES (NULL), (90);
237 INSERT INTO t1 VALUES (NULL);
240 UPDATE t1 SET c1 = 150 WHERE c1 = 17;
241 UPDATE t1 SET c1 = 151 WHERE c1 = 19;
243 UPDATE t1 SET c1 = 140 WHERE c1 = 150;
244 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=
'test'
246 UPDATE t1 SET c1 = NULL WHERE c1 = 4;
247 INSERT INTO t1 VALUES (NULL);
248 INSERT INTO t1 VALUES (NULL);
250 SELECT * FROM t1
ORDER BY c1;
253 -- echo #
Test with auto_increment_increment and auto_increment_offset.
254 eval CREATE
TABLE t1 (
255 c1 INT NOT NULL AUTO_INCREMENT,
258 PARTITION BY
HASH(c1)
260 let $old_increment = `SELECT @@session.auto_increment_increment`;
261 let $old_offset = `SELECT @@session.auto_increment_offset`;
262 SET @@session.auto_increment_increment = 10;
263 SET @@session.auto_increment_offset = 5;
264 INSERT INTO t1 VALUES (1);
265 INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
266 SET @@session.auto_increment_increment = 5;
267 SET @@session.auto_increment_offset = 3;
268 INSERT INTO t1 VALUES (NULL);
269 let $new_val = `SELECT LAST_INSERT_ID()`;
270 eval INSERT INTO t1 VALUES ($new_val + 1);
271 INSERT INTO t1 VALUES (NULL);
272 let $new_val = `SELECT LAST_INSERT_ID()`;
273 eval INSERT INTO t1 VALUES ($new_val + 2);
274 INSERT INTO t1 VALUES (NULL);
275 let $new_val = `SELECT LAST_INSERT_ID()`;
276 eval INSERT INTO t1 VALUES ($new_val + 3);
277 INSERT INTO t1 VALUES (NULL);
278 let $new_val = `SELECT LAST_INSERT_ID()`;
279 eval INSERT INTO t1 VALUES ($new_val + 4);
280 INSERT INTO t1 VALUES (NULL);
281 let $new_val = `SELECT LAST_INSERT_ID()`;
282 eval INSERT INTO t1 VALUES ($new_val + 5);
283 INSERT INTO t1 VALUES (NULL);
284 let $new_val = `SELECT LAST_INSERT_ID()`;
285 eval INSERT INTO t1 VALUES ($new_val + 6);
286 INSERT INTO t1 VALUES (NULL);
287 eval SET @@session.auto_increment_increment = $old_increment;
288 eval SET @@session.auto_increment_offset = $old_offset;
289 SELECT * FROM t1
ORDER BY c1;
293 -- echo
# Test reported auto_increment value
294 eval CREATE
TABLE t1 (
295 c1 INT NOT NULL AUTO_INCREMENT,
298 PARTITION BY
HASH (c1)
300 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
302 INSERT INTO t1 VALUES (2);
303 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
305 INSERT INTO t1 VALUES (4);
306 INSERT INTO t1 VALUES (NULL);
307 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
309 INSERT INTO t1 VALUES (NULL);
310 INSERT INTO t1 VALUES (17);
311 INSERT INTO t1 VALUES (19);
312 INSERT INTO t1 VALUES (NULL);
313 INSERT INTO t1 VALUES (NULL);
314 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
316 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='
test'
318 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
319 INSERT INTO t1 VALUES (10);
322 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
324 SELECT * FROM t1
ORDER BY c1;
325 INSERT INTO t1 VALUES (NULL);
326 SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=
'test'
328 INSERT INTO t1 VALUES (NULL);
329 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
330 INSERT INTO t1 VALUES (15);
333 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
335 INSERT INTO t1 VALUES (NULL);
336 SELECT * FROM t1
ORDER BY c1;
337 INSERT INTO t1 VALUES (NULL);
342 INSERT INTO t1 VALUES (NULL);
343 SHOW CREATE
TABLE t1;
344 SELECT * FROM t1
ORDER BY c1;
349 INSERT INTO t1 VALUES (NULL);
350 SHOW CREATE
TABLE t1;
351 SELECT * FROM t1
ORDER BY c1;
352 INSERT INTO t1 VALUES (100);
353 INSERT INTO t1 VALUES (NULL);
356 DELETE FROM t1 WHERE c1 >= 100;
358 # InnoDB does reset auto_increment on OPTIMIZE, Bug#18274
360 SHOW CREATE
TABLE t1;
363 -- echo #
Test with two threads
365 -- echo # con
default
366 eval CREATE
TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY (c1))
368 PARTITION BY
HASH(c1)
370 INSERT INTO t1 (c1) VALUES (2);
371 INSERT INTO t1 (c1) VALUES (4);
372 connect(con1, localhost, root,,);
375 INSERT INTO t1 (c1) VALUES (NULL);
376 INSERT INTO t1 (c1) VALUES (10);
378 -- echo
# con default
379 INSERT INTO t1 (c1) VALUES (NULL);
380 INSERT INTO t1 (c1) VALUES (NULL);
381 INSERT INTO t1 (c1) VALUES (19);
382 INSERT INTO t1 (c1) VALUES (21);
385 INSERT INTO t1 (c1) VALUES (NULL);
387 -- echo
# con default
388 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
389 INSERT INTO t1 (c1) VALUES (16);
392 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
396 INSERT INTO t1 (c1) VALUES (NULL);
399 -- echo
# con default
400 INSERT INTO t1 (c1) VALUES (NULL);
401 SELECT * FROM t1
ORDER BY c1;
404 -- echo
# Test with two threads + start transaction NO PARTITIONING
405 connect(con1, localhost, root,,);
407 -- echo # con
default
408 eval CREATE
TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY (c1))
411 INSERT INTO t1 (c1) VALUES (2);
412 INSERT INTO t1 (c1) VALUES (4);
416 INSERT INTO t1 (c1) VALUES (NULL);
417 INSERT INTO t1 (c1) VALUES (10);
419 -- echo
# con default
420 INSERT INTO t1 (c1) VALUES (NULL);
421 INSERT INTO t1 (c1) VALUES (NULL);
422 INSERT INTO t1 (c1) VALUES (19);
423 INSERT INTO t1 (c1) VALUES (21);
426 INSERT INTO t1 (c1) VALUES (NULL);
428 -- echo
# con default
429 -- error 0, ER_DUP_KEY
430 INSERT INTO t1 (c1) VALUES (16);
433 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
437 INSERT INTO t1 (c1) VALUES (NULL);
438 SELECT * FROM t1
ORDER BY c1;
440 SELECT * FROM t1
ORDER BY c1;
443 -- echo
# con default
444 INSERT INTO t1 (c1) VALUES (NULL);
445 SELECT * FROM t1
ORDER BY c1;
447 SELECT * FROM t1
ORDER BY c1;
450 -- echo
# Test with two threads + start transaction
451 connect(con1, localhost, root,,);
453 -- echo # con
default
454 eval CREATE
TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY (c1))
456 PARTITION BY
HASH(c1)
459 INSERT INTO t1 (c1) VALUES (2);
460 INSERT INTO t1 (c1) VALUES (4);
464 INSERT INTO t1 (c1) VALUES (NULL), (10);
466 -- echo
# con default
467 INSERT INTO t1 (c1) VALUES (NULL), (NULL), (19);
468 INSERT INTO t1 (c1) VALUES (21);
471 INSERT INTO t1 (c1) VALUES (NULL);
473 -- echo
# con default
474 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
475 INSERT INTO t1 (c1) VALUES (16);
478 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
482 INSERT INTO t1 (c1) VALUES (NULL);
483 SELECT * FROM t1
ORDER BY c1;
485 SELECT * FROM t1
ORDER BY c1;
488 -- echo
# con default
489 INSERT INTO t1 (c1) VALUES (NULL);
490 SELECT * FROM t1
ORDER BY c1;
492 SELECT * FROM t1
ORDER BY c1;
497 -- echo #
Test with another column after
498 eval CREATE
TABLE t1 (
499 c1 INT NOT NULL AUTO_INCREMENT,
503 PARTITION BY
HASH(c2)
505 INSERT INTO t1 VALUES (1, 0);
506 INSERT INTO t1 VALUES (1, 1);
507 INSERT INTO t1 VALUES (NULL, 1), (NULL, 2), (NULL, 3);
508 INSERT INTO t1 VALUES (NULL, 3);
509 INSERT INTO t1 VALUES (2, 0), (NULL, 2);
510 INSERT INTO t1 VALUES (2, 2);
511 INSERT INTO t1 VALUES (2, 22);
512 INSERT INTO t1 VALUES (NULL, 2);
513 SELECT * FROM t1
ORDER BY c1,c2;
517 -- echo
# Test with another column before
518 eval CREATE
TABLE t1 (
520 c2 INT NOT NULL AUTO_INCREMENT,
523 PARTITION BY
HASH(c2)
525 INSERT INTO t1 VALUES (1, 0);
526 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
527 INSERT INTO t1 VALUES (1, 1);
530 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
531 echo # mysql_errno: $mysql_errno;
533 INSERT INTO t1 VALUES (1, NULL);
534 INSERT INTO t1 VALUES (2, NULL), (3, 11), (3, NULL), (2, 0);
535 INSERT INTO t1 VALUES (2, NULL);
536 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
537 INSERT INTO t1 VALUES (2, 2);
540 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
541 echo # mysql_errno: $mysql_errno;
543 INSERT INTO t1 VALUES (2, 22);
544 INSERT INTO t1 VALUES (2, NULL);
545 SELECT * FROM t1
ORDER BY c1,c2;
548 -- echo #
Test with auto_increment on secondary column in multi-column-
index
549 -- disable_abort_on_error
550 eval CREATE
TABLE t1 (
552 c2 INT NOT NULL AUTO_INCREMENT,
555 PARTITION BY
HASH(c2)
557 -- enable_abort_on_error
559 eval SET @my_errno= $mysql_errno ;
560 let $run = `SELECT @my_errno = 0`;
561 # ER_WRONG_AUTO_KEY is 1075
562 let $ER_WRONG_AUTO_KEY= 1075;
563 if (`SELECT @my_errno NOT IN (0,$ER_WRONG_AUTO_KEY)`)
565 -- echo # Unknown error
code, exits
571 INSERT INTO t1 VALUES (1, 0);
572 -- error 0, ER_DUP_KEY, ER_DUP_ENTRY
573 INSERT INTO t1 VALUES (1, 1);
576 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
577 echo # mysql_errno: $mysql_errno;
579 INSERT INTO t1 VALUES (1, NULL);
580 INSERT INTO t1 VALUES (2, NULL);
581 INSERT INTO t1 VALUES (3, NULL);
582 INSERT INTO t1 VALUES (3, NULL), (2, 0), (2, NULL);
583 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
584 INSERT INTO t1 VALUES (2, 2);
587 echo # ERROR (only OK
if Blackhole/NDB) should give ER_DUP_KEY or ER_DUP_ENTRY;
588 echo
# mysql_errno: $mysql_errno;
590 INSERT INTO t1 VALUES (2, 22), (2, NULL);
591 SELECT * FROM t1
ORDER BY c1,c2;
595 -- echo #
Test AUTO_INCREMENT in CREATE
596 eval CREATE
TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY (c1))
599 PARTITION BY
HASH(c1)
601 SHOW CREATE
TABLE t1;
602 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
603 INSERT INTO t1 (c1) VALUES (4);
606 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
608 SHOW CREATE
TABLE t1;
609 INSERT INTO t1 (c1) VALUES (0);
610 SHOW CREATE
TABLE t1;
611 INSERT INTO t1 (c1) VALUES (NULL);
612 SHOW CREATE
TABLE t1;
613 SELECT * FROM t1
ORDER BY c1;
615 -- echo
# Test sql_mode 'NO_AUTO_VALUE_ON_ZERO'
616 let $old_sql_mode = `select @@session.sql_mode`;
617 SET @@session.sql_mode =
'NO_AUTO_VALUE_ON_ZERO';
618 INSERT INTO t1 (c1) VALUES (300);
619 SHOW CREATE
TABLE t1;
620 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
621 INSERT INTO t1 (c1) VALUES (0);
624 echo # ERROR (only OK
if Archive) mysql_errno: $mysql_errno;
626 SHOW CREATE
TABLE t1;
627 INSERT INTO t1 (c1) VALUES (NULL);
628 SHOW CREATE
TABLE t1;
629 SELECT * FROM t1
ORDER BY c1;
630 eval SET @@session.sql_mode = '$old_sql_mode';
633 -- echo
# Test SET INSERT_ID
634 eval CREATE
TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY (c1))
636 PARTITION BY
HASH(c1)
638 SHOW CREATE
TABLE t1;
639 INSERT INTO t1 (c1) VALUES (NULL);
640 SHOW CREATE
TABLE t1;
643 SHOW CREATE
TABLE t1;
644 INSERT INTO t1 (c1) VALUES (NULL);
645 SHOW CREATE
TABLE t1;
647 -- error 0, ER_DUP_ENTRY, ER_DUP_KEY
648 INSERT INTO t1 VALUES (NULL), (NULL), (NULL);
651 echo # ERROR (only OK
if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY;
652 echo # mysql_errno: $mysql_errno;
654 INSERT INTO t1 VALUES (NULL);
655 SELECT * FROM t1
ORDER BY c1;
658 -- echo # Testing with FLUSH
TABLE
659 eval CREATE
TABLE t1 (
660 c1 INT NOT NULL AUTO_INCREMENT,
663 PARTITION BY
HASH(c1)
665 SHOW CREATE
TABLE t1;
667 SHOW CREATE TABLE t1;
668 INSERT INTO t1 VALUES (4);
670 SHOW CREATE TABLE t1;
671 INSERT INTO t1 VALUES (NULL);
673 SHOW CREATE TABLE t1;
674 SELECT * FROM t1
ORDER BY c1;
677 if (!$skip_negative_auto_inc)
679 --echo #############################################################################
680 --echo # Bug #45823 - Assertion failure in
file row/row0mysql.c line 1386
681 --echo # Bug #43988 - AUTO_INCREMENT
errors with partitioned InnoDB tables in 5.1.31
682 --echo ##############################################################################
684 --echo # Inserting negative autoincrement values into a partition
table (partitions >= 4)
686 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
687 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
689 INSERT INTO t(c2) VALUES (10);
690 INSERT INTO t(c2) VALUES (20);
691 --error 0, ER_DUP_KEY
692 INSERT INTO t VALUES (-1,-10);
695 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
697 INSERT INTO t(c2) VALUES (30);
698 INSERT INTO t(c2) VALUES (40);
700 SELECT * FROM t
ORDER BY c1 ASC;
704 --echo
# Reading from a partition table (partitions >= 2 ) after inserting a negative
705 --echo # value into the
auto increment column
708 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
709 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 2;
711 --error 0, ER_DUP_KEY
712 INSERT INTO t VALUES (-2,-20);
715 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
717 INSERT INTO t(c2) VALUES (30);
719 SELECT * FROM t
ORDER BY c1 ASC;
723 --echo
# Inserting negative auto increment value into a partition table (partitions >= 2)
724 --echo #
auto increment value > 2.
726 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
727 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 2;
729 --error 0, ER_DUP_KEY
730 INSERT INTO t VALUES (-4,-20);
733 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
735 INSERT INTO t(c2) VALUES (30);
736 INSERT INTO t(c2) VALUES (40);
738 SELECT * FROM t
ORDER BY c1 ASC;
742 --echo
# Inserting -1 into autoincrement column of a partition table (partition >= 4)
744 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
745 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
747 INSERT INTO t(c2) VALUES (10);
748 INSERT INTO t(c2) VALUES (20);
749 --error 0, ER_DUP_KEY
750 INSERT INTO t VALUES (-1,-10);
753 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
756 SELECT * FROM t
ORDER BY c1 ASC;
758 INSERT INTO t(c2) VALUES (30);
760 SELECT * FROM t
ORDER BY c1 ASC;
764 --echo
# Deleting from an auto increment table after inserting negative values
766 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
767 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
769 INSERT INTO t(c2) VALUES (10);
770 INSERT INTO t(c2) VALUES (20);
771 --error 0, ER_DUP_KEY
772 INSERT INTO t VALUES (-1,-10);
775 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
777 INSERT INTO t(c2) VALUES (30);
778 --error 0, ER_DUP_KEY
779 INSERT INTO t VALUES (-3,-20);
782 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
784 INSERT INTO t(c2) VALUES (40);
786 SELECT * FROM t
ORDER BY c1 ASC;
790 DELETE FROM t WHERE c1 > 1;
793 SELECT * FROM t
ORDER BY c1 ASC;
797 --echo # Inserting a positive value that exceeds maximum allowed value
for an
798 --echo # Auto Increment column (positive maximum)
800 eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
801 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
803 INSERT INTO t(c2) VALUES (10);
804 INSERT INTO t(c2) VALUES (20);
805 INSERT INTO t VALUES (126,30);
806 INSERT INTO t VALUES (127,40);
808 --error 0, ER_DUP_ENTRY, ER_DUP_KEY
809 INSERT INTO t VALUES (128,50);
812 echo # ERROR (Only OK
if Blackhole);
813 echo # expecting ER_DUP_ENTRY or ER_DUP_KEY, mysql_errno: $mysql_errno;
815 --error 0, ER_DUP_ENTRY, ER_DUP_KEY
816 INSERT INTO t VALUES (129,60);
819 echo # ERROR (only OK
if Blackhole);
820 echo # expecting ER_DUP_ENTRY or ER_DUP_KEY, mysql_errno: $mysql_errno;
823 SELECT * FROM t
ORDER BY c1 ASC;
827 --echo # Inserting a negative value that goes below minimum allowed value
for an
828 --echo # Auto Increment column (negative minimum)
830 eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
831 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
833 INSERT INTO t(c2) VALUES (10);
834 INSERT INTO t(c2) VALUES (20);
835 --error 0, ER_DUP_KEY
836 INSERT INTO t VALUES (-127,30);
839 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
841 --error 0, ER_DUP_KEY
842 INSERT INTO t VALUES (-128,40);
845 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
848 --error 0, ER_DUP_ENTRY, ER_DUP_KEY
849 INSERT INTO t VALUES (-129,50);
852 echo # ERROR (only OK
if Blackhole)
853 echo # should give ER_DUP_KEY or ER_DUP_ENTRY mysql_errno: $mysql_errno;
855 --error 0, ER_DUP_ENTRY, ER_DUP_KEY
856 INSERT INTO t VALUES (-130,60);
859 echo # ERROR (only OK
if Blackhole)
860 echo # should give ER_DUP_KEY or ER_DUP_ENTRY mysql_errno: $mysql_errno;
863 SELECT * FROM t
ORDER BY c1 ASC;
867 --echo # Updating the partition
table with a negative Auto Increment value
869 eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
870 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
872 INSERT INTO t(c2) VALUES (10);
873 INSERT INTO t(c2) VALUES (20);
874 --error 0, ER_DUP_KEY
875 INSERT INTO t VALUES (-1,-10);
878 echo # ERROR (only OK
if Archive), mysql_errno: $mysql_errno;
880 INSERT INTO t(c2) VALUES (30);
882 SELECT * FROM t
ORDER BY c1 ASC;
886 UPDATE t SET c1 = -6 WHERE c1 = 2;
889 SELECT * FROM t
ORDER BY c1 ASC;
891 INSERT INTO t(c2) VALUES (40);
892 INSERT INTO t(c2) VALUES (50);
896 UPDATE t SET c1 = -6 WHERE c1 = 2;
899 SELECT * FROM t
ORDER BY c1 ASC;
903 --echo # Updating the partition
table with a value that crosses the upper limits
904 --echo # on
both the positive and the negative side.
906 eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY
KEY(c1),
907 c2 INT) ENGINE=$engine PARTITION BY
HASH(c1) PARTITIONS 4;
909 INSERT INTO t(c2) VALUES (10);
910 INSERT INTO t(c2) VALUES (20);
911 INSERT INTO t VALUES (126,30);
912 INSERT INTO t VALUES (127,40);
914 SELECT * FROM t
ORDER BY c1 ASC;
918 UPDATE t SET c1 = 130 where c1 = 127;
921 SELECT * FROM t
ORDER BY c1 ASC;
925 UPDATE t SET c1 = -140 where c1 = 126;
928 SELECT * FROM t
ORDER BY c1 ASC;
935 (a INT NULL AUTO_INCREMENT,
938 PARTITION BY
KEY(a) PARTITIONS 2;
939 SET LAST_INSERT_ID = 999;
941 INSERT INTO t1 SET a = 1 ON DUPLICATE
KEY UPDATE a = NULL;
942 SELECT LAST_INSERT_ID();
944 INSERT INTO t1 SET a = 1 ON DUPLICATE
KEY UPDATE a = NULL;
945 SELECT LAST_INSERT_ID();
947 UPDATE t1 SET a = 1 WHERE a IS NULL;
948 SELECT LAST_INSERT_ID();
950 UPDATE t1 SET a = NULL WHERE a = 1;
951 SELECT LAST_INSERT_ID();
957 --echo
##############################################################################