diff --git a/executor/builder.go b/executor/builder.go index 93528e1611504..9f417b9d427da 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -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) @@ -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, diff --git a/executor/executor_test.go b/executor/executor_test.go index 2c40b47382440..7b3df5060e59b 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -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) { diff --git a/go.mod b/go.mod index 5ce9b13d9bde7..dd5e03490ff35 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 2ea5436c0eea2..40dacd628a329 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/planner/core/common_plans.go b/planner/core/common_plans.go index 0566415198c85..5d4e6a8368b14 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -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 diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index ca317f950cab8..8166957b81162 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -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, diff --git a/planner/core/initialize.go b/planner/core/initialize.go index 186038a95bc86..a46e928e09dee 100644 --- a/planner/core/initialize.go +++ b/planner/core/initialize.go @@ -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. @@ -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) @@ -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) diff --git a/planner/core/logical_plans.go b/planner/core/logical_plans.go index afe988226839a..48bdf0b7fecab 100644 --- a/planner/core/logical_plans.go +++ b/planner/core/logical_plans.go @@ -864,3 +864,10 @@ type LogicalShow struct { logicalSchemaProducer ShowContents } + +// LogicalShowDDLJobs is for showing DDL job list. +type LogicalShowDDLJobs struct { + logicalSchemaProducer + + JobNumber int64 +} diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 745ba64f11375..5d6884ed8e477 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -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{ diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 197cdd7720c25..c65b08389d0b0 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -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()) diff --git a/planner/core/stats.go b/planner/core/stats.go index 516273a32a92f..972dc2021d169 100644 --- a/planner/core/stats.go +++ b/planner/core/stats.go @@ -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 } diff --git a/planner/core/stringer.go b/planner/core/stringer.go index 32a71833661c9..532f8610703da 100644 --- a/planner/core/stringer.go +++ b/planner/core/stringer.go @@ -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: