Skip to content

Commit

Permalink
ddl: refine sql to get ddl jobs (#39245)
Browse files Browse the repository at this point in the history
close #39244
  • Loading branch information
wjhuang2016 authored Nov 22, 2022
1 parent d15ffca commit 8b39e66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ bazel-out
bazel-testlogs
bazel-tidb
.ijwb/
/oom_record/
25 changes: 25 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,28 @@ func TestTiDBDownBeforeUpdateGlobalVersion(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/mockDownBeforeUpdateGlobalVersion"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/ddl/checkDownBeforeUpdateGlobalVersion"))
}

func TestDDLBlockedCreateView(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int)")

hook := &ddl.TestDDLCallback{Do: dom}
first := true
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.SchemaState != model.StateWriteOnly {
return
}
if !first {
return
}
first = false
tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use test")
tk2.MustExec("create view v as select * from t")
}
dom.DDL().SetHook(hook)
tk.MustExec("alter table t modify column a char(10)")
}
2 changes: 1 addition & 1 deletion ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (dc *ddlCtx) excludeJobIDs() string {
}

const (
getJobSQL = "select job_meta, processing from mysql.tidb_ddl_job where job_id in (select min(job_id) from mysql.tidb_ddl_job group by schema_ids, table_ids, processing order by processing desc limit 1) and %s reorg %s order by processing desc, job_id"
getJobSQL = "select job_meta, processing from mysql.tidb_ddl_job where job_id in (select min(job_id) from mysql.tidb_ddl_job group by schema_ids, table_ids, processing) and %s reorg %s order by processing desc, job_id"
)

type jobType int
Expand Down

0 comments on commit 8b39e66

Please sign in to comment.