diff --git a/ddl/db_test.go b/ddl/db_test.go index 5990df4634a68..a061af75baf26 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -1763,3 +1763,23 @@ func TestDDLBlockedCreateView(t *testing.T) { dom.DDL().SetHook(hook) tk.MustExec("alter table t modify column a char(10)") } + +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") +} diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index d188854686491..81a43935b056f 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -288,7 +288,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