Skip to content

Commit

Permalink
infoschema: adjust column type for information_schema.analyze_status (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyifangreeneyes authored May 17, 2022
1 parent d2ada35 commit 828a255
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
7 changes: 6 additions & 1 deletion executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2490,8 +2490,13 @@ func FinishAnalyzeJob(ctx sessionctx.Context, job *statistics.AnalyzeJob, analyz
// process_id is used to see which process is running the analyze job and kill the analyze job. After the analyze job
// is finished(or failed), process_id is useless and we set it to NULL to avoid `kill tidb process_id` wrongly.
if analyzeErr != nil {
failReason := analyzeErr.Error()
const textMaxLength = 65535
if len(failReason) > textMaxLength {
failReason = failReason[:textMaxLength]
}
sql = "UPDATE mysql.analyze_jobs SET processed_rows = processed_rows + %?, end_time = CONVERT_TZ(%?, '+00:00', @@TIME_ZONE), state = %?, fail_reason = %?, process_id = NULL WHERE id = %?"
args = []interface{}{job.Progress.GetDeltaCount(), job.EndTime.UTC().Format(types.TimeFormat), statistics.AnalyzeFailed, analyzeErr.Error(), *job.ID}
args = []interface{}{job.Progress.GetDeltaCount(), job.EndTime.UTC().Format(types.TimeFormat), statistics.AnalyzeFailed, failReason, *job.ID}
} else {
sql = "UPDATE mysql.analyze_jobs SET processed_rows = processed_rows + %?, end_time = CONVERT_TZ(%?, '+00:00', @@TIME_ZONE), state = %?, process_id = NULL WHERE id = %?"
args = []interface{}{job.Progress.GetDeltaCount(), job.EndTime.UTC().Format(types.TimeFormat), statistics.AnalyzeFinished, *job.ID}
Expand Down
14 changes: 14 additions & 0 deletions executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@ func TestForAnalyzeStatus(t *testing.T) {
store, dom, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()
tk := testkit.NewTestKit(t, store)
analyzeStatusTable := "CREATE TABLE `ANALYZE_STATUS` (\n" +
" `TABLE_SCHEMA` varchar(64) DEFAULT NULL,\n" +
" `TABLE_NAME` varchar(64) DEFAULT NULL,\n" +
" `PARTITION_NAME` varchar(64) DEFAULT NULL,\n" +
" `JOB_INFO` longtext DEFAULT NULL,\n" +
" `PROCESSED_ROWS` bigint(64) unsigned DEFAULT NULL,\n" +
" `START_TIME` datetime DEFAULT NULL,\n" +
" `END_TIME` datetime DEFAULT NULL,\n" +
" `STATE` varchar(64) DEFAULT NULL,\n" +
" `FAIL_REASON` longtext DEFAULT NULL,\n" +
" `INSTANCE` varchar(512) DEFAULT NULL,\n" +
" `PROCESS_ID` bigint(64) unsigned DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
tk.MustQuery("show create table information_schema.analyze_status").Check(testkit.Rows("ANALYZE_STATUS " + analyzeStatusTable))
tk.MustExec("delete from mysql.analyze_jobs")
tk.MustExec("use test")
tk.MustExec("drop table if exists analyze_test")
Expand Down
6 changes: 3 additions & 3 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,13 @@ var tableAnalyzeStatusCols = []columnInfo{
{name: "TABLE_SCHEMA", tp: mysql.TypeVarchar, size: 64},
{name: "TABLE_NAME", tp: mysql.TypeVarchar, size: 64},
{name: "PARTITION_NAME", tp: mysql.TypeVarchar, size: 64},
{name: "JOB_INFO", tp: mysql.TypeVarchar, size: types.UnspecifiedLength},
{name: "JOB_INFO", tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: "PROCESSED_ROWS", tp: mysql.TypeLonglong, size: 64, flag: mysql.UnsignedFlag},
{name: "START_TIME", tp: mysql.TypeDatetime},
{name: "END_TIME", tp: mysql.TypeDatetime},
{name: "STATE", tp: mysql.TypeVarchar, size: 64},
{name: "FAIL_REASON", tp: mysql.TypeVarchar, size: types.UnspecifiedLength},
{name: "INSTANCE", tp: mysql.TypeVarchar, size: 64},
{name: "FAIL_REASON", tp: mysql.TypeLongBlob, size: types.UnspecifiedLength},
{name: "INSTANCE", tp: mysql.TypeVarchar, size: 512},
{name: "PROCESS_ID", tp: mysql.TypeLonglong, size: 64, flag: mysql.UnsignedFlag},
}

Expand Down
7 changes: 6 additions & 1 deletion statistics/handle/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,13 @@ func (h *Handle) InsertAnalyzeJob(job *statistics.AnalyzeJob, instance string, p
defer h.mu.Unlock()
exec := h.mu.ctx.(sqlexec.RestrictedSQLExecutor)
ctx := context.TODO()
jobInfo := job.JobInfo
const textMaxLength = 65535
if len(jobInfo) > textMaxLength {
jobInfo = jobInfo[:textMaxLength]
}
const insertJob = "INSERT INTO mysql.analyze_jobs (table_schema, table_name, partition_name, job_info, state, instance, process_id) VALUES (%?, %?, %?, %?, %?, %?, %?)"
_, _, err := exec.ExecRestrictedSQL(ctx, []sqlexec.OptionFuncAlias{sqlexec.ExecOptionUseCurSession}, insertJob, job.DBName, job.TableName, job.PartitionName, job.JobInfo, statistics.AnalyzePending, instance, procID)
_, _, err := exec.ExecRestrictedSQL(ctx, []sqlexec.OptionFuncAlias{sqlexec.ExecOptionUseCurSession}, insertJob, job.DBName, job.TableName, job.PartitionName, jobInfo, statistics.AnalyzePending, instance, procID)
if err != nil {
return err
}
Expand Down

0 comments on commit 828a255

Please sign in to comment.