From 896ee778a28b60ce86ca4a03a68d3fa80cb62f42 Mon Sep 17 00:00:00 2001 From: xia Date: Wed, 6 Jan 2016 12:40:10 +0800 Subject: [PATCH] *: address comments --- executor/executor.go | 22 ++++++++++++++-------- executor/executor_test.go | 1 + optimizer/plan/alternatives.go | 17 ++--------------- optimizer/plan/planbuilder.go | 18 ++++++------------ 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/executor/executor.go b/executor/executor.go index 2fccd1ab33..a2c481950a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -91,7 +91,7 @@ type Executor interface { type ShowDDL struct { fields []*ast.ResultField ctx context.Context - cnt int + done bool } // Fields implements Executor Fields interface. @@ -101,7 +101,7 @@ func (e *ShowDDL) Fields() []*ast.ResultField { // Next implements Execution Next interface. func (e *ShowDDL) Next() (*Row, error) { - if e.cnt != 0 { + if e.done { return nil, nil } @@ -115,23 +115,23 @@ func (e *ShowDDL) Next() (*Row, error) { return nil, errors.Trace(err) } - records := []interface{}{ + rowData := []interface{}{ info.SchemaVer, nil, nil, } if info.Owner != nil { - records[1] = info.Owner.String() + rowData[1] = info.Owner.String() } if info.Job != nil { - records[2] = info.Job.String() + rowData[2] = info.Job.String() } row := &Row{} - row.Data = append(row.Data, records...) + row.Data = rowData for i, f := range e.fields { - f.Expr.SetValue(records[i]) + f.Expr.SetValue(rowData[i]) } - e.cnt++ + e.done = true return row, nil } @@ -145,6 +145,7 @@ func (e *ShowDDL) Close() error { type CheckTable struct { tables []*ast.TableName ctx context.Context + done bool } // Fields implements Executor Fields interface. @@ -154,6 +155,10 @@ func (e *CheckTable) Fields() []*ast.ResultField { // Next implements Execution Next interface. func (e *CheckTable) Next() (*Row, error) { + if e.done { + return nil, nil + } + dbName := model.NewCIStr(db.GetCurrentSchema(e.ctx)) is := sessionctx.GetDomain(e.ctx).InfoSchema() txn, err := e.ctx.GetTxn(false) @@ -173,6 +178,7 @@ func (e *CheckTable) Next() (*Row, error) { } } } + e.done = true return nil, nil } diff --git a/executor/executor_test.go b/executor/executor_test.go index 25f3a4ea2c..07b823b6cd 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -53,6 +53,7 @@ func (s *testSuite) TestAdmin(c *C) { c.Assert(err, IsNil) row, err := r.Next() c.Assert(err, IsNil) + c.Logf("row:%v\n", row) c.Assert(row, NotNil) r, err = tk.Exec("admin check table admin_test") diff --git a/optimizer/plan/alternatives.go b/optimizer/plan/alternatives.go index 4b28147d3a..94d6692234 100644 --- a/optimizer/plan/alternatives.go +++ b/optimizer/plan/alternatives.go @@ -23,16 +23,14 @@ func Alternatives(p Plan) ([]Plan, error) { case nil: case *TableScan: plans = tableScanAlternatives(x) - case *ShowDDL: - plans = showDDLAlternatives(x) - case *CheckTable: - plans = checkTableAlternatives(x) case WithSrcPlan: var err error plans, err = planWithSrcAlternatives(x) if err != nil { return nil, errors.Trace(err) } + case *ShowDDL: + case *CheckTable: case *Prepare: case *Execute: case *Deallocate: @@ -67,17 +65,6 @@ func tableScanAlternatives(p *TableScan) []Plan { return alts } -func showDDLAlternatives(p *ShowDDL) []Plan { - sp := &ShowDDL{} - sp.SetFields(p.fields) - - return []Plan{sp} -} - -func checkTableAlternatives(p *CheckTable) []Plan { - return []Plan{&CheckTable{}} -} - // planWithSrcAlternatives shallow copies the WithSrcPlan, // and set its src to src alternatives. func planWithSrcAlternatives(p WithSrcPlan) ([]Plan, error) { diff --git a/optimizer/plan/planbuilder.go b/optimizer/plan/planbuilder.go index 79c8ba2e4f..18ec8e8970 100644 --- a/optimizer/plan/planbuilder.go +++ b/optimizer/plan/planbuilder.go @@ -34,9 +34,6 @@ const ( CodeUnsupportedType = iota + 1 ) -// Table Name. -const tableShowDDL = "SHOW_DDL" - // BuildPlan builds a plan from a node. // returns ErrUnsupportedType if ast.Node type is not supported yet. func BuildPlan(node ast.Node) (Plan, error) { @@ -216,11 +213,7 @@ func (b *planBuilder) buildPrepare(x *ast.PrepareStmt) Plan { func (b *planBuilder) buildAdmin(adm *ast.AdminStmt) Plan { if adm.Tp == ast.AdminCheckTable { - if adm.Tables != nil { - return &CheckTable{Tables: adm.Tables} - } - - return nil + return &CheckTable{Tables: adm.Tables} } if adm.Tp == ast.AdminShowDDL { @@ -230,15 +223,16 @@ func (b *planBuilder) buildAdmin(adm *ast.AdminStmt) Plan { return p } + b.err = ErrUnsupportedType.Gen("Unsupported type %T", adm) + return nil } func buildShowDDLFields() []*ast.ResultField { - tbName := tableShowDDL rfs := make([]*ast.ResultField, 0, 3) - rfs = append(rfs, buildResultField(tbName, "SCHEMA_VER", mysql.TypeLonglong, 4)) - rfs = append(rfs, buildResultField(tbName, "OWNER", mysql.TypeVarchar, 64)) - rfs = append(rfs, buildResultField(tbName, "Job", mysql.TypeVarchar, 128)) + rfs = append(rfs, buildResultField("", "SCHEMA_VER", mysql.TypeLonglong, 4)) + rfs = append(rfs, buildResultField("", "OWNER", mysql.TypeVarchar, 64)) + rfs = append(rfs, buildResultField("", "Job", mysql.TypeVarchar, 128)) return rfs }