Skip to content

Commit

Permalink
*: support where in admin show ddl jobs statement (#12484)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored Oct 11, 2019
1 parent c0d6185 commit ebc122b
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 15 deletions.
4 changes: 2 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (b *executorBuilder) build(p plannercore.Plan) Executor {
return b.buildShowNextRowID(v)
case *plannercore.ShowDDL:
return b.buildShowDDL(v)
case *plannercore.ShowDDLJobs:
case *plannercore.PhysicalShowDDLJobs:
return b.buildShowDDLJobs(v)
case *plannercore.ShowDDLJobQueries:
return b.buildShowDDLJobQueries(v)
Expand Down Expand Up @@ -284,7 +284,7 @@ func (b *executorBuilder) buildShowDDL(v *plannercore.ShowDDL) Executor {
return e
}

func (b *executorBuilder) buildShowDDLJobs(v *plannercore.ShowDDLJobs) Executor {
func (b *executorBuilder) buildShowDDLJobs(v *plannercore.PhysicalShowDDLJobs) Executor {
e := &ShowDDLJobsExec{
jobNumber: v.JobNumber,
is: b.is,
Expand Down
4 changes: 4 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ func (s *testSuite) TestAdminShowDDLJobs(c *C) {
re = tk.MustQuery("admin show ddl jobs 1")
row = re.Rows()[0]
c.Assert(row[1], Equals, "test_admin_show_ddl_jobs")

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")
}

func (s *testSuite) TestAdminChecksumOfPartitionedTable(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e
github.com/pingcap/kvproto v0.0.0-20190910074005-0e61b6f435c1
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd
github.com/pingcap/parser v0.0.0-20190923031704-33636bc5e5d6
github.com/pingcap/parser v0.0.0-20191011021308-7586d610b7aa
github.com/pingcap/pd v1.1.0-beta.0.20190923032047-5c648dc365e0
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible
github.com/pingcap/tipb v0.0.0-20191008064422-018b2fadf414
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ github.com/pingcap/kvproto v0.0.0-20190910074005-0e61b6f435c1 h1:DNvxkdcjA0TBIII
github.com/pingcap/kvproto v0.0.0-20190910074005-0e61b6f435c1/go.mod h1:QMdbTAXCHzzygQzqcG9uVUgU2fKeSN1GmfMiykdSzzY=
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd h1:hWDol43WY5PGhsh3+8794bFHY1bPrmu6bTalpssCrGg=
github.com/pingcap/log v0.0.0-20190715063458-479153f07ebd/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw=
github.com/pingcap/parser v0.0.0-20190923031704-33636bc5e5d6 h1:PyjsTUD8gJ6QGilbwiy/TTn89J84/69Pj9LixOd/fFE=
github.com/pingcap/parser v0.0.0-20190923031704-33636bc5e5d6/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/parser v0.0.0-20191011021308-7586d610b7aa h1:jZtG+lBvIHjii6ClHjnEAdqsDbRobxDcVauFETBfAME=
github.com/pingcap/parser v0.0.0-20191011021308-7586d610b7aa/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v1.1.0-beta.0.20190923032047-5c648dc365e0 h1:GIEq+wZfrl2bcJxpuSrEH4H7/nlf5YdmpS+dU9lNIt8=
github.com/pingcap/pd v1.1.0-beta.0.20190923032047-5c648dc365e0/go.mod h1:G/6rJpnYwM0LKMec2rI82/5Kg6GaZMvlfB+e6/tvYmI=
github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible h1:MkWCxgZpJBgY2f4HtwWMMFzSBb3+JPzeJgF3VrXE/bU=
Expand Down
7 changes: 0 additions & 7 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ type ShowDDL struct {
baseSchemaProducer
}

// ShowDDLJobs is for showing DDL job list.
type ShowDDLJobs struct {
baseSchemaProducer

JobNumber int64
}

// ShowSlow is for showing slow queries.
type ShowSlow struct {
baseSchemaProducer
Expand Down
9 changes: 9 additions & 0 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ func (p *LogicalShow) findBestTask(prop *property.PhysicalProperty) (task, error
return &rootTask{p: pShow}, nil
}

func (p *LogicalShowDDLJobs) findBestTask(prop *property.PhysicalProperty) (task, error) {
if !prop.IsEmpty() {
return invalidTask, nil
}
pShow := PhysicalShowDDLJobs{JobNumber: p.JobNumber}.Init(p.ctx)
pShow.SetSchema(p.schema)
return &rootTask{p: pShow}, nil
}

// findBestTask implements LogicalPlan interface.
func (p *baseLogicalPlan) findBestTask(prop *property.PhysicalProperty) (bestTask task, err error) {
// If p is an inner plan in an IndexJoin, the IndexJoin will generate an inner plan by itself,
Expand Down
16 changes: 16 additions & 0 deletions planner/core/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const (
TypeTableGather = "TableGather"
// TypeIndexMerge is the type of IndexMergeReader
TypeIndexMerge = "IndexMerge"
// TypeShowDDLJobs is the type of show ddl jobs.
TypeShowDDLJobs = "ShowDDLJobs"
)

// Init initializes LogicalAggregation.
Expand Down Expand Up @@ -293,6 +295,12 @@ func (p LogicalShow) Init(ctx sessionctx.Context) *LogicalShow {
return &p
}

// Init initializes LogicalShowDDLJobs.
func (p LogicalShowDDLJobs) Init(ctx sessionctx.Context) *LogicalShowDDLJobs {
p.baseLogicalPlan = newBaseLogicalPlan(ctx, TypeShowDDLJobs, &p, 0)
return &p
}

// Init initializes PhysicalShow.
func (p PhysicalShow) Init(ctx sessionctx.Context) *PhysicalShow {
p.basePhysicalPlan = newBasePhysicalPlan(ctx, TypeShow, &p, 0)
Expand All @@ -301,6 +309,14 @@ func (p PhysicalShow) Init(ctx sessionctx.Context) *PhysicalShow {
return &p
}

// Init initializes PhysicalShowDDLJobs.
func (p PhysicalShowDDLJobs) Init(ctx sessionctx.Context) *PhysicalShowDDLJobs {
p.basePhysicalPlan = newBasePhysicalPlan(ctx, TypeShowDDLJobs, &p, 0)
// Just use pseudo stats to avoid panic.
p.stats = &property.StatsInfo{RowCount: 1}
return &p
}

// Init initializes LogicalLock.
func (p LogicalLock) Init(ctx sessionctx.Context) *LogicalLock {
p.baseLogicalPlan = newBaseLogicalPlan(ctx, TypeLock, &p, 0)
Expand Down
7 changes: 7 additions & 0 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,10 @@ type LogicalShow struct {
logicalSchemaProducer
ShowContents
}

// LogicalShowDDLJobs is for showing DDL job list.
type LogicalShowDDLJobs struct {
logicalSchemaProducer

JobNumber int64
}
7 changes: 7 additions & 0 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,13 @@ type PhysicalShow struct {
ShowContents
}

// PhysicalShowDDLJobs is for showing DDL job list.
type PhysicalShowDDLJobs struct {
physicalSchemaProducer

JobNumber int64
}

// BuildMergeJoinPlan builds a PhysicalMergeJoin from the given fields. Currently, it is only used for test purpose.
func BuildMergeJoinPlan(ctx sessionctx.Context, joinType JoinType, leftKeys, rightKeys []*expression.Column) *PhysicalMergeJoin {
baseJoin := basePhysicalJoin{
Expand Down
11 changes: 10 additions & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,18 @@ func (b *PlanBuilder) buildAdmin(ctx context.Context, as *ast.AdminStmt) (Plan,
p.SetSchema(buildShowDDLFields())
ret = p
case ast.AdminShowDDLJobs:
p := &ShowDDLJobs{JobNumber: as.JobNumber}
p := LogicalShowDDLJobs{JobNumber: as.JobNumber}.Init(b.ctx)
p.SetSchema(buildShowDDLJobsFields())
for _, col := range p.schema.Columns {
col.UniqueID = b.ctx.GetSessionVars().AllocPlanColumnID()
}
ret = p
if as.Where != nil {
ret, err = b.buildSelection(ctx, p, as.Where, nil)
if err != nil {
return nil, err
}
}
case ast.AdminCancelDDLJobs:
p := &CancelDDLJobs{JobIDs: as.JobIDs}
p.SetSchema(buildCancelDDLJobsFields())
Expand Down
15 changes: 13 additions & 2 deletions planner/core/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ func (p *LogicalTableDual) DeriveStats(childStats []*property.StatsInfo) (*prope
// DeriveStats implement LogicalPlan DeriveStats interface.
func (p *LogicalShow) DeriveStats(childStats []*property.StatsInfo) (*property.StatsInfo, error) {
// A fake count, just to avoid panic now.
p.stats = getFakeStats(p.Schema().Len())
return p.stats, nil
}

func getFakeStats(length int) *property.StatsInfo {
profile := &property.StatsInfo{
RowCount: 1,
Cardinality: make([]float64, p.Schema().Len()),
Cardinality: make([]float64, length),
}
for i := range profile.Cardinality {
profile.Cardinality[i] = 1
}
p.stats = profile
return profile
}

// DeriveStats implement LogicalPlan DeriveStats interface.
func (p *LogicalShowDDLJobs) DeriveStats(childStats []*property.StatsInfo) (*property.StatsInfo, error) {
// A fake count, just to avoid panic now.
p.stats = getFakeStats(p.Schema().Len())
return p.stats, nil
}

Expand Down
2 changes: 2 additions & 0 deletions planner/core/stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func toString(in Plan, strs []string, idxs []int) ([]string, []int) {
str = "ShowDDL"
case *LogicalShow, *PhysicalShow:
str = "Show"
case *LogicalShowDDLJobs, *PhysicalShowDDLJobs:
str = "ShowDDLJobs"
case *LogicalSort, *PhysicalSort:
str = "Sort"
case *LogicalJoin:
Expand Down

0 comments on commit ebc122b

Please sign in to comment.