Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner, ddl: fix hash partition with adding new column (#39574) #39589

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7596,3 +7596,23 @@ func (s *testDBSuite8) TestCreateTextAdjustLen(c *C) {
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"))
tk.MustExec("drop table if exists t")
}

func TestHashPartitionAddColumn(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int, b int) partition by hash(a) partitions 4")

hook := &ddl.TestDDLCallback{Do: dom}
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.SchemaState != model.StateWriteOnly {
return
}
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
tk2.MustExec("delete from t")
}
dom.DDL().SetHook(hook)
tk.MustExec("alter table t add column c int")
}
3 changes: 2 additions & 1 deletion planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ func (s *partitionProcessor) pruneHashPartition(ctx sessionctx.Context, tbl tabl
// please see https://github.com/pingcap/tidb/issues/22635 for more details.
func (s *partitionProcessor) reconstructTableColNames(ds *DataSource) ([]*types.FieldName, error) {
names := make([]*types.FieldName, 0, len(ds.TblCols))
colsInfo := ds.table.FullHiddenColsAndVisibleCols()
// Use DeletableCols to get all the columns.
colsInfo := ds.table.DeletableCols()
colsInfoMap := make(map[int64]*table.Column, len(colsInfo))
for _, c := range colsInfo {
colsInfoMap[c.ID] = c
Expand Down