Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: support where in admin show ddl jobs statement #12484

Merged
merged 12 commits into from
Oct 11, 2019
Merged
4 changes: 2 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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 @@ -282,7 +282,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
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (s *testSuite) TestAdminShowDDLJobs(c *C) {
err = tk.Se.CommitTxn(context.Background())
c.Assert(err, IsNil)

re = tk.MustQuery("admin show ddl jobs 1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to add some case to admin show ddl jobs 1 where ... instead of deleting the former case.

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")
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ require (
)

go 1.13

replace github.com/pingcap/parser => github.com/crazycs520/parser v0.0.0-20190929091254-85344bdd5ae3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the parser PR have merged?

4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142/go.mod h1:F5haX7
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/crazycs520/parser v0.0.0-20190929091254-85344bdd5ae3 h1:/fZiYheQ4yHpQbPvEkUWj5DuCaEX5fInDKE4UVjwqjI=
github.com/crazycs520/parser v0.0.0-20190929091254-85344bdd5ae3/go.mod h1:xLjI+gnWYexq011WPMEvCNS8rFM9qe1vdojIEzSKPuc=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso=
github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs9mPDVNRekM7lKScauxd5kXTr1Mfyig6TDM=
github.com/cznic/sortutil v0.0.0-20150617083342-4c7342852e65 h1:hxuZop6tSoOi0sxFzoGGYdRqNrPubyaIf9KoBG9tPiE=
Expand Down Expand Up @@ -164,8 +166,6 @@ 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/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 @@ -109,6 +109,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 @@ -91,6 +91,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 @@ -291,6 +293,12 @@ func (p LogicalShow) Init(ctx sessionctx.Context) *LogicalShow {
return &p
}

// Init initializes LogicalShow.
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -299,6 +307,14 @@ func (p PhysicalShow) Init(ctx sessionctx.Context) *PhysicalShow {
return &p
}

// Init initializes PhysicalShow.
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -518,6 +518,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
15 changes: 13 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,20 @@ 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())
ret = p
for _, col := range p.schema.Columns {
col.UniqueID = b.ctx.GetSessionVars().AllocPlanColumnID()
}
var np LogicalPlan
np = p
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
if as.Where != nil {
np, err = b.buildSelection(ctx, np, as.Where, nil)
if err != nil {
return nil, err
}
}
ret = np
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