@@ -1106,3 +1106,41 @@ func TestRenameMultiTables(t *testing.T) {
1106
1106
tk .MustExec ("drop database rename2" )
1107
1107
tk .MustExec ("drop database rename3" )
1108
1108
}
1109
+
1110
+ func TestDefShardTables (t * testing.T ) {
1111
+ store := testkit .CreateMockStore (t , mockstore .WithDDLChecker ())
1112
+
1113
+ tk := testkit .NewTestKit (t , store )
1114
+
1115
+ tk .MustExec ("set @@session.tidb_enable_clustered_index = off" )
1116
+ tk .MustExec ("set @@session.tidb_shard_row_id_bits = 4" )
1117
+ tk .MustExec ("set @@session.tidb_pre_split_regions = 4" )
1118
+ tk .MustExec ("use test" )
1119
+ tk .MustExec ("create table t (i int primary key)" )
1120
+ result := tk .MustQuery ("show create table t" )
1121
+ createSQL := result .Rows ()[0 ][1 ]
1122
+ expected := "CREATE TABLE `t` (\n `i` int(11) NOT NULL,\n PRIMARY KEY (`i`) /*T![clustered_index] NONCLUSTERED */\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=4 PRE_SPLIT_REGIONS=4 */"
1123
+ require .Equal (t , expected , createSQL )
1124
+
1125
+ // test for manual setup shard_row_id_bits and pre_split_regions
1126
+ tk .MustExec ("create table t0 (i int primary key) /*T! SHARD_ROW_ID_BITS=2 PRE_SPLIT_REGIONS=2 */" )
1127
+ result = tk .MustQuery ("show create table t0" )
1128
+ createSQL = result .Rows ()[0 ][1 ]
1129
+ expected = "CREATE TABLE `t0` (\n `i` int(11) NOT NULL,\n PRIMARY KEY (`i`) /*T![clustered_index] NONCLUSTERED */\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=2 PRE_SPLIT_REGIONS=2 */"
1130
+ require .Equal (t , expected , createSQL )
1131
+
1132
+ // test for clustered index table
1133
+ tk .MustExec ("set @@session.tidb_enable_clustered_index = on" )
1134
+ tk .MustExec ("create table t1 (i int primary key)" )
1135
+ result = tk .MustQuery ("show create table t1" )
1136
+ createSQL = result .Rows ()[0 ][1 ]
1137
+ expected = "CREATE TABLE `t1` (\n `i` int(11) NOT NULL,\n PRIMARY KEY (`i`) /*T![clustered_index] CLUSTERED */\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
1138
+ require .Equal (t , expected , createSQL )
1139
+
1140
+ // test for global temporary table
1141
+ tk .MustExec ("create global temporary table tengine (id int) engine = 'innodb' on commit delete rows" )
1142
+ result = tk .MustQuery ("show create table tengine" )
1143
+ createSQL = result .Rows ()[0 ][1 ]
1144
+ expected = "CREATE GLOBAL TEMPORARY TABLE `tengine` (\n `id` int(11) DEFAULT NULL\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS"
1145
+ require .Equal (t , expected , createSQL )
1146
+ }
0 commit comments