From 69ae17813dbdd36ac49ffe4bb6c32c7ee49fbbd6 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 23 Mar 2023 23:40:42 +0800 Subject: [PATCH] parser, ddl: correct the job type of 'REORGANIZE PARTITION' (#42490) (#42494) close pingcap/tidb#42442 --- parser/model/ddl.go | 2 +- parser/model/ddl_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/parser/model/ddl.go b/parser/model/ddl.go index b922242dcd10f..23638519e01d9 100644 --- a/parser/model/ddl.go +++ b/parser/model/ddl.go @@ -758,7 +758,7 @@ func (job *Job) NotStarted() bool { // MayNeedReorg indicates that this job may need to reorganize the data. func (job *Job) MayNeedReorg() bool { switch job.Type { - case ActionAddIndex, ActionAddPrimaryKey: + case ActionAddIndex, ActionAddPrimaryKey, ActionReorganizePartition: return true case ActionModifyColumn: if len(job.CtxVars) > 0 { diff --git a/parser/model/ddl_test.go b/parser/model/ddl_test.go index 7ea82606363ce..04d2992aed939 100644 --- a/parser/model/ddl_test.go +++ b/parser/model/ddl_test.go @@ -71,3 +71,34 @@ func TestBackfillMetaCodec(t *testing.T) { bmRet.Decode(bmBytes) require.Equal(t, bm, bmRet) } + +func TestMayNeedReorg(t *testing.T) { + //TODO(bb7133): add more test cases for different ActionType. + reorgJobTypes := []model.ActionType{ + model.ActionReorganizePartition, + model.ActionAddIndex, + model.ActionAddPrimaryKey, + } + generalJobTypes := []model.ActionType{ + model.ActionCreateTable, + model.ActionDropTable, + } + job := &model.Job{ + ID: 100, + Type: model.ActionCreateTable, + SchemaID: 101, + TableID: 102, + SchemaName: "test", + TableName: "t", + State: model.JobStateDone, + MultiSchemaInfo: nil, + } + for _, jobType := range reorgJobTypes { + job.Type = jobType + require.True(t, job.MayNeedReorg()) + } + for _, jobType := range generalJobTypes { + job.Type = jobType + require.False(t, job.MayNeedReorg()) + } +}