Skip to content

Commit dde5ab3

Browse files
authored
pkg/ddl: fix exchange partition metadata mismatch for shard_row_id_bits (#66632)
close #66077
1 parent a171feb commit dde5ab3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pkg/ddl/create_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ func BuildTableInfoWithStmt(ctx *metabuild.Context, s *ast.CreateTableStmt, dbCh
825825
// set default shard row id bits and pre-split regions for table.
826826
if !tbInfo.HasClusteredIndex() && tbInfo.TempTableType == model.TempTableNone {
827827
tbInfo.ShardRowIDBits = ctx.GetShardRowIDBits()
828+
tbInfo.MaxShardRowIDBits = tbInfo.ShardRowIDBits
828829
tbInfo.PreSplitRegions = ctx.GetPreSplitRegions()
829830
}
830831

pkg/ddl/tests/partition/db_partition_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,3 +4173,41 @@ func TestExchangeTiDBRowID(t *testing.T) {
41734173
"6 6 3",
41744174
"8 8 30001"))
41754175
}
4176+
4177+
func TestIssue66077ExchangePartitionDifferentDefinitionsWithShardRowIDBits(t *testing.T) {
4178+
store := testkit.CreateMockStore(t)
4179+
tk := testkit.NewTestKit(t, store)
4180+
tk.MustExec("set @@session.tidb_enable_clustered_index = off")
4181+
tk.MustExec("set @@session.tidb_shard_row_id_bits = 4")
4182+
tk.MustExec("create database sbtest")
4183+
tk.MustExec("use sbtest")
4184+
4185+
tk.MustExec(`CREATE TABLE sbtest1 (
4186+
id int NOT NULL,
4187+
k int NOT NULL DEFAULT '0',
4188+
c char(120) NOT NULL DEFAULT '',
4189+
pad char(60) NOT NULL DEFAULT '',
4190+
PRIMARY KEY (id) /*T![clustered_index] NONCLUSTERED */,
4191+
KEY k_1 (k)
4192+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin`)
4193+
4194+
tblInfo, err := tk.Session().GetInfoSchema().TableInfoByName(ast.NewCIStr("sbtest"), ast.NewCIStr("sbtest1"))
4195+
require.NoError(t, err)
4196+
require.Equal(t, uint64(4), tblInfo.ShardRowIDBits)
4197+
require.Equal(t, uint64(4), tblInfo.MaxShardRowIDBits)
4198+
4199+
tk.MustExec(`CREATE TABLE sbtest1_partition (
4200+
id int NOT NULL,
4201+
k int NOT NULL DEFAULT '0',
4202+
c char(120) NOT NULL DEFAULT '',
4203+
pad char(60) NOT NULL DEFAULT '',
4204+
PRIMARY KEY (id) /*T![clustered_index] NONCLUSTERED */,
4205+
KEY k_1 (k)
4206+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=4 */
4207+
PARTITION BY RANGE (id)
4208+
(PARTITION 1M VALUES LESS THAN (1000000),
4209+
PARTITION 5M VALUES LESS THAN (5000000),
4210+
PARTITION 10M VALUES LESS THAN (10000000),
4211+
PARTITION 100M VALUES LESS THAN (100000000))`)
4212+
tk.MustExec("alter table sbtest1_partition exchange partition 1M with table sbtest1")
4213+
}

0 commit comments

Comments
 (0)