Skip to content

Commit

Permalink
ddl: DDL job add charset and collate when create the index (#42750)
Browse files Browse the repository at this point in the history
close #42748
  • Loading branch information
3AceShowHand authored Apr 6, 2023
1 parent 575b652 commit 915b39b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6703,6 +6703,7 @@ func (d *ddl) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast.Inde
}

tzName, tzOffset := ddlutil.GetTimeZone(ctx)
charset, collate := ctx.GetSessionVars().GetCharsetInfo()
job := &model.Job{
SchemaID: schema.ID,
TableID: t.Meta().ID,
Expand All @@ -6718,6 +6719,8 @@ func (d *ddl) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast.Inde
},
Args: []interface{}{unique, indexName, indexPartSpecifications, indexOption, hiddenCols, global},
Priority: ctx.GetSessionVars().DDLReorgPriority,
Charset: charset,
Collate: collate,
}

err = d.DoDDLJob(ctx, job)
Expand Down
3 changes: 3 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ func (w *worker) onCreateIndex(d *ddlCtx, t *meta.Meta, job *model.Job, isPK boo
if job.ReorgMeta.ReorgTp == model.ReorgTypeLitMerge {
ingest.LitBackCtxMgr.Unregister(job.ID)
}
logutil.BgLogger().Info("[ddl] run add index job done",
zap.String("charset", job.Charset),
zap.String("collation", job.Collate))
default:
err = dbterror.ErrInvalidDDLState.GenWithStackByArgs("index", tblInfo.State)
}
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ func TestBatchInsertDelete(t *testing.T) {
kv.TxnTotalSizeLimit.Store(originLimit)
}()
// Set the limitation to a small value, make it easier to reach the limitation.
kv.TxnTotalSizeLimit.Store(5900)
kv.TxnTotalSizeLimit.Store(6000)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down
7 changes: 7 additions & 0 deletions parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ func (sub *SubJob) ToProxyJob(parentJob *Job) Job {
MultiSchemaInfo: &MultiSchemaInfo{Revertible: sub.Revertible},
Priority: parentJob.Priority,
SeqNum: parentJob.SeqNum,
Charset: parentJob.Charset,
Collate: parentJob.Collate,
}
}

Expand Down Expand Up @@ -423,6 +425,11 @@ type Job struct {

// SeqNum is the total order in all DDLs, it's used to identify the order of DDL.
SeqNum uint64 `json:"seq_num"`

// Charset is the charset when the DDL Job is created.
Charset string `json:"charset"`
// Collate is the collation the DDL Job is created.
Collate string `json:"collate"`
}

// FinishTableJob is called when a job is finished.
Expand Down
2 changes: 1 addition & 1 deletion parser/model/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestJobSize(t *testing.T) {
- SubJob.ToProxyJob()
`
job := model.Job{}
require.Equal(t, 288, int(unsafe.Sizeof(job)), msg)
require.Equal(t, 320, int(unsafe.Sizeof(job)), msg)
}

func TestBackfillMetaCodec(t *testing.T) {
Expand Down

0 comments on commit 915b39b

Please sign in to comment.