diff --git a/ddl/ddl_worker.go b/ddl/ddl_worker.go index 804e9870e3ca7..0f1040bbfdb12 100644 --- a/ddl/ddl_worker.go +++ b/ddl/ddl_worker.go @@ -762,6 +762,9 @@ func (w *worker) runDDLJob(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, logutil.Logger(w.logCtx).Info("[ddl] run DDL job", zap.String("job", job.String())) timeStart := time.Now() + if job.RealStartTS == 0 { + job.RealStartTS = t.StartTS + } defer func() { metrics.DDLWorkerHistogram.WithLabelValues(metrics.WorkerRunDDLJob, job.Type.String(), metrics.RetLabel(err)).Observe(time.Since(timeStart).Seconds()) }() diff --git a/executor/executor.go b/executor/executor.go index 8b0d0e58dcf35..b912873917a26 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -509,7 +509,8 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che tableName = getTableName(e.is, job.TableID) } - startTime := ts2Time(job.StartTS) + createTime := ts2Time(job.StartTS) + startTime := ts2Time(job.RealStartTS) finishTime := ts2Time(finishTS) // Check the privilege. @@ -525,13 +526,18 @@ func (e *DDLJobRetriever) appendJobToChunk(req *chunk.Chunk, job *model.Job, che req.AppendInt64(5, job.SchemaID) req.AppendInt64(6, job.TableID) req.AppendInt64(7, job.RowCount) - req.AppendTime(8, startTime) - if finishTS > 0 { - req.AppendTime(9, finishTime) + req.AppendTime(8, createTime) + if job.RealStartTS > 0 { + req.AppendTime(9, startTime) } else { req.AppendNull(9) } - req.AppendString(10, job.State.String()) + if finishTS > 0 { + req.AppendTime(10, finishTime) + } else { + req.AppendNull(10) + } + req.AppendString(11, job.State.String()) } func ts2Time(timestamp uint64) types.Time { diff --git a/executor/executor_test.go b/executor/executor_test.go index 476d70b29e8ee..3b398bcabfdf0 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -426,7 +426,7 @@ func (s *testSuite3) TestAdmin(c *C) { err = r.Next(ctx, req) c.Assert(err, IsNil) row = req.GetRow(0) - c.Assert(row.Len(), Equals, 11) + c.Assert(row.Len(), Equals, 12) txn, err = s.store.Begin() c.Assert(err, IsNil) historyJobs, err := admin.GetHistoryDDLJobs(txn, admin.DefNumHistoryJobs) @@ -442,7 +442,7 @@ func (s *testSuite3) TestAdmin(c *C) { err = r.Next(ctx, req) c.Assert(err, IsNil) row = req.GetRow(0) - c.Assert(row.Len(), Equals, 11) + c.Assert(row.Len(), Equals, 12) c.Assert(row.GetInt64(0), Equals, historyJobs[0].ID) c.Assert(err, IsNil) @@ -569,13 +569,13 @@ func (s *testSuiteP2) TestAdminShowDDLJobs(c *C) { re = tk.MustQuery("admin show ddl jobs 1 where job_type='create table'") row = re.Rows()[0] c.Assert(row[1], Equals, "test_admin_show_ddl_jobs") - c.Assert(row[9], Equals, "") + c.Assert(row[10], Equals, "") // Test the START_TIME and END_TIME field. re = tk.MustQuery("admin show ddl jobs where job_type = 'create table' and start_time > str_to_date('20190101','%Y%m%d%H%i%s')") row = re.Rows()[0] c.Assert(row[2], Equals, "t") - c.Assert(row[9], Equals, "") + c.Assert(row[10], Equals, "") } func (s *testSuiteP2) TestAdminShowDDLJobsInfo(c *C) { diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 1e4d56858316d..42ee1b155e6e9 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -1191,7 +1191,7 @@ func (e *DDLJobsReaderExec) Next(ctx context.Context, req *chunk.Chunk) error { num := mathutil.Min(req.Capacity(), len(e.runningJobs)-e.cursor) for i := e.cursor; i < e.cursor+num; i++ { e.appendJobToChunk(req, e.runningJobs[i], checker) - req.AppendString(11, e.runningJobs[i].Query) + req.AppendString(12, e.runningJobs[i].Query) } e.cursor += num count += num @@ -1206,7 +1206,7 @@ func (e *DDLJobsReaderExec) Next(ctx context.Context, req *chunk.Chunk) error { } for _, job := range e.cacheJobs { e.appendJobToChunk(req, job, checker) - req.AppendString(11, job.Query) + req.AppendString(12, job.Query) } e.cursor += len(e.cacheJobs) } diff --git a/infoschema/tables.go b/infoschema/tables.go index afee75ce12490..84b1296e3b517 100644 --- a/infoschema/tables.go +++ b/infoschema/tables.go @@ -1160,6 +1160,7 @@ var tableDDLJobsCols = []columnInfo{ {name: "SCHEMA_ID", tp: mysql.TypeLonglong, size: 21}, {name: "TABLE_ID", tp: mysql.TypeLonglong, size: 21}, {name: "ROW_COUNT", tp: mysql.TypeLonglong, size: 21}, + {name: "CREATE_TIME", tp: mysql.TypeDatetime, size: 19}, {name: "START_TIME", tp: mysql.TypeDatetime, size: 19}, {name: "END_TIME", tp: mysql.TypeDatetime, size: 19}, {name: "STATE", tp: mysql.TypeVarchar, size: 64}, diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index edf7d0d79544f..61d8a1c9b0dea 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -2689,7 +2689,7 @@ func buildCleanupIndexFields() (*expression.Schema, types.NameSlice) { } func buildShowDDLJobsFields() (*expression.Schema, types.NameSlice) { - schema := newColumnsWithNames(11) + schema := newColumnsWithNames(12) schema.Append(buildColumnWithName("", "JOB_ID", mysql.TypeLonglong, 4)) schema.Append(buildColumnWithName("", "DB_NAME", mysql.TypeVarchar, 64)) schema.Append(buildColumnWithName("", "TABLE_NAME", mysql.TypeVarchar, 64)) @@ -2698,6 +2698,7 @@ func buildShowDDLJobsFields() (*expression.Schema, types.NameSlice) { schema.Append(buildColumnWithName("", "SCHEMA_ID", mysql.TypeLonglong, 4)) schema.Append(buildColumnWithName("", "TABLE_ID", mysql.TypeLonglong, 4)) schema.Append(buildColumnWithName("", "ROW_COUNT", mysql.TypeLonglong, 4)) + schema.Append(buildColumnWithName("", "CREATE_TIME", mysql.TypeDatetime, 19)) schema.Append(buildColumnWithName("", "START_TIME", mysql.TypeDatetime, 19)) schema.Append(buildColumnWithName("", "END_TIME", mysql.TypeDatetime, 19)) schema.Append(buildColumnWithName("", "STATE", mysql.TypeVarchar, 64))