@@ -606,7 +606,7 @@ func TestAutoIDIncrementAndOffset(t *testing.T) {
606
606
for _ , str := range []string {"" , " AUTO_ID_CACHE 1" } {
607
607
tk .MustExec (`create table io (a int key auto_increment)` + str )
608
608
tk .MustExec (`insert into io values (null),(null),(null)` )
609
- tk .MustQuery (`select * from io` ).Check (testkit .Rows ("10 " , "15 " , "20 " ))
609
+ tk .MustQuery (`select * from io` ).Check (testkit .Rows ("1 " , "6 " , "11 " ))
610
610
tk .MustExec (`drop table io` )
611
611
}
612
612
@@ -616,23 +616,23 @@ func TestAutoIDIncrementAndOffset(t *testing.T) {
616
616
tk .Session ().GetSessionVars ().AutoIncrementOffset = 10
617
617
tk .Session ().GetSessionVars ().AutoIncrementIncrement = 2
618
618
tk .MustExec (`insert into io values (),(),()` )
619
- tk .MustQuery (`select * from io` ).Check (testkit .Rows ("10 " , "12 " , "14 " ))
619
+ tk .MustQuery (`select * from io` ).Check (testkit .Rows ("1 " , "3 " , "5 " ))
620
620
tk .MustExec (`delete from io` )
621
621
622
622
// Test reset the increment.
623
623
tk .Session ().GetSessionVars ().AutoIncrementIncrement = 5
624
624
tk .MustExec (`insert into io values (),(),()` )
625
- tk .MustQuery (`select * from io` ).Check (testkit .Rows ("15 " , "20 " , "25 " ))
625
+ tk .MustQuery (`select * from io` ).Check (testkit .Rows ("6 " , "11 " , "16 " ))
626
626
tk .MustExec (`delete from io` )
627
627
628
628
tk .Session ().GetSessionVars ().AutoIncrementIncrement = 10
629
629
tk .MustExec (`insert into io values (),(),()` )
630
- tk .MustQuery (`select * from io` ).Check (testkit .Rows ("30 " , "40 " , "50 " ))
630
+ tk .MustQuery (`select * from io` ).Check (testkit .Rows ("20 " , "30 " , "40 " ))
631
631
tk .MustExec (`delete from io` )
632
632
633
633
tk .Session ().GetSessionVars ().AutoIncrementIncrement = 5
634
634
tk .MustExec (`insert into io values (),(),()` )
635
- tk .MustQuery (`select * from io` ).Check (testkit .Rows ("55 " , "60 " , "65 " ))
635
+ tk .MustQuery (`select * from io` ).Check (testkit .Rows ("41 " , "46 " , "51 " ))
636
636
tk .MustExec (`drop table io` )
637
637
}
638
638
@@ -643,10 +643,10 @@ func TestAutoIDIncrementAndOffset(t *testing.T) {
643
643
tk .MustExec (`create table io (a int, b int auto_increment, key(b))` + str )
644
644
tk .MustExec (`insert into io(b) values (null),(null),(null)` )
645
645
// AutoID allocation will take increment and offset into consideration.
646
- tk .MustQuery (`select b from io` ).Check (testkit .Rows ("10 " , "12 " , "14 " ))
646
+ tk .MustQuery (`select b from io` ).Check (testkit .Rows ("1 " , "3 " , "5 " ))
647
647
if str == "" {
648
648
// HandleID allocation will ignore the increment and offset.
649
- tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("15 " , "16 " , "17 " ))
649
+ tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("6 " , "7 " , "8 " ))
650
650
} else {
651
651
// Separate row id and auto inc id, increment and offset works on auto inc id
652
652
tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("1" , "2" , "3" ))
@@ -655,9 +655,9 @@ func TestAutoIDIncrementAndOffset(t *testing.T) {
655
655
656
656
tk .Session ().GetSessionVars ().AutoIncrementIncrement = 10
657
657
tk .MustExec (`insert into io(b) values (null),(null),(null)` )
658
- tk .MustQuery (`select b from io` ).Check (testkit .Rows ("20 " , "30 " , "40 " ))
658
+ tk .MustQuery (`select b from io` ).Check (testkit .Rows ("10 " , "20 " , "30 " ))
659
659
if str == "" {
660
- tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("41 " , "42 " , "43 " ))
660
+ tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("31 " , "32 " , "33 " ))
661
661
} else {
662
662
tk .MustQuery (`select _tidb_rowid from io` ).Check (testkit .Rows ("4" , "5" , "6" ))
663
663
}
@@ -768,3 +768,43 @@ func TestIssue39528(t *testing.T) {
768
768
// Make sure the code does not visit tikv on allocate path.
769
769
require .False (t , codeRun )
770
770
}
771
+
772
+ func TestIssue52622 (t * testing.T ) {
773
+ store := testkit .CreateMockStore (t )
774
+
775
+ tk := testkit .NewTestKit (t , store )
776
+ tk .MustExec ("use test" )
777
+ tk .MustExec (`set @@auto_increment_increment = 66;` )
778
+ tk .MustExec (`set @@auto_increment_offset = 9527;` )
779
+
780
+ tk .MustQuery (`select @@auto_increment_increment;` ).Check (testkit .Rows ("66" ))
781
+ tk .MustQuery (`select @@auto_increment_offset;` ).Check (testkit .Rows ("9527" ))
782
+
783
+ for i := 0 ; i < 2 ; i ++ {
784
+ createTableSQL := "create table issue52622 (id int primary key auto_increment, k int)"
785
+ if i == 0 {
786
+ createTableSQL = createTableSQL + " AUTO_ID_CACHE 1"
787
+ }
788
+
789
+ tk .MustExec (createTableSQL )
790
+ tk .MustExec ("insert into issue52622 (k) values (1),(2),(3);" )
791
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" ))
792
+ if i == 0 {
793
+ tk .MustQuery ("show create table issue52622" ).CheckContain ("134" )
794
+ }
795
+ tk .MustExec ("insert into issue52622 (k) values (4);" )
796
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" , "199 4" ))
797
+
798
+ tk .MustExec ("truncate table issue52622;" )
799
+ tk .MustExec ("insert into issue52622 (k) values (1)" )
800
+ tk .MustExec ("insert into issue52622 (k) values (2)" )
801
+ tk .MustExec ("insert into issue52622 (k) values (3)" )
802
+ if i == 0 {
803
+ tk .MustQuery ("show create table issue52622" ).CheckContain ("134" )
804
+ }
805
+ tk .MustExec ("insert into issue52622 (k) values (4);" )
806
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" , "199 4" ))
807
+
808
+ tk .MustExec ("drop table issue52622;" )
809
+ }
810
+ }
0 commit comments