diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index e440d33591d93..ba9b8cc137492 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -466,6 +466,7 @@ func (w *worker) finishDDLJob(t *meta.Meta, job *model.Job) (err error) { updateRawArgs = false } w.writeDDLSeqNum(job) + w.jobContext.resetWhenJobFinish() err = t.AddHistoryDDLJob(job, updateRawArgs) return errors.Trace(err) } @@ -520,17 +521,16 @@ func newMetaWithQueueTp(txn kv.Transaction, tp workerType) *meta.Meta { func (w *jobContext) setDDLLabelForTopSQL(job *model.Job) { if !topsqlstate.TopSQLEnabled() || job == nil { - w.cacheDigest = nil - w.ddlJobCtx = context.Background() return } if job.Query != w.cacheSQL || w.cacheDigest == nil { w.cacheNormalizedSQL, w.cacheDigest = parser.NormalizeDigest(job.Query) w.cacheSQL = job.Query + w.ddlJobCtx = topsql.AttachSQLInfo(context.Background(), w.cacheNormalizedSQL, w.cacheDigest, "", nil, false) + } else { + topsql.AttachSQLInfo(w.ddlJobCtx, w.cacheNormalizedSQL, w.cacheDigest, "", nil, false) } - - w.ddlJobCtx = topsql.AttachSQLInfo(context.Background(), w.cacheNormalizedSQL, w.cacheDigest, "", nil, false) } func (w *jobContext) getResourceGroupTaggerForTopSQL() tikvrpc.ResourceGroupTagger { @@ -546,6 +546,13 @@ func (w *jobContext) getResourceGroupTaggerForTopSQL() tikvrpc.ResourceGroupTagg return tagger } +func (w *jobContext) resetWhenJobFinish() { + w.ddlJobCtx = context.Background() + w.cacheSQL = "" + w.cacheDigest = nil + w.cacheNormalizedSQL = "" +} + // handleDDLJobQueue handles DDL jobs in DDL Job queue. func (w *worker) handleDDLJobQueue(d *ddlCtx) error { once := true