@@ -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
}
@@ -806,3 +806,43 @@ func TestAutoIDConstraint(t *testing.T) {
806
806
tk .MustExec ("create table tt2 (id int, c int auto_increment, key c_idx(c))" )
807
807
tk .MustExec ("alter table tt2 drop index c_idx" )
808
808
}
809
+
810
+ func TestIssue52622 (t * testing.T ) {
811
+ store := testkit .CreateMockStore (t )
812
+
813
+ tk := testkit .NewTestKit (t , store )
814
+ tk .MustExec ("use test" )
815
+ tk .MustExec (`set @@auto_increment_increment = 66;` )
816
+ tk .MustExec (`set @@auto_increment_offset = 9527;` )
817
+
818
+ tk .MustQuery (`select @@auto_increment_increment;` ).Check (testkit .Rows ("66" ))
819
+ tk .MustQuery (`select @@auto_increment_offset;` ).Check (testkit .Rows ("9527" ))
820
+
821
+ for i := 0 ; i < 2 ; i ++ {
822
+ createTableSQL := "create table issue52622 (id int primary key auto_increment, k int)"
823
+ if i == 0 {
824
+ createTableSQL = createTableSQL + " AUTO_ID_CACHE 1"
825
+ }
826
+
827
+ tk .MustExec (createTableSQL )
828
+ tk .MustExec ("insert into issue52622 (k) values (1),(2),(3);" )
829
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" ))
830
+ if i == 0 {
831
+ tk .MustQuery ("show create table issue52622" ).CheckContain ("134" )
832
+ }
833
+ tk .MustExec ("insert into issue52622 (k) values (4);" )
834
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" , "199 4" ))
835
+
836
+ tk .MustExec ("truncate table issue52622;" )
837
+ tk .MustExec ("insert into issue52622 (k) values (1)" )
838
+ tk .MustExec ("insert into issue52622 (k) values (2)" )
839
+ tk .MustExec ("insert into issue52622 (k) values (3)" )
840
+ if i == 0 {
841
+ tk .MustQuery ("show create table issue52622" ).CheckContain ("134" )
842
+ }
843
+ tk .MustExec ("insert into issue52622 (k) values (4);" )
844
+ tk .MustQuery ("select * from issue52622" ).Check (testkit .Rows ("1 1" , "67 2" , "133 3" , "199 4" ))
845
+
846
+ tk .MustExec ("drop table issue52622;" )
847
+ }
848
+ }
0 commit comments