Skip to content

Commit

Permalink
Merge pull request pingcap#909 from pingcap/coocood/show
Browse files Browse the repository at this point in the history
executor: support Show statement.
  • Loading branch information
coocood committed Feb 19, 2016
2 parents c818e51 + 58e667f commit 37585a0
Show file tree
Hide file tree
Showing 11 changed files with 690 additions and 60 deletions.
1 change: 1 addition & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ const (
// See: https://dev.mysql.com/doc/refman/5.7/en/show.html
type ShowStmt struct {
dmlNode
resultSetNode

Tp ShowStmtType // Databases/Tables/Columns/....
DBName string
Expand Down
24 changes: 24 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"github.com/pingcap/tidb/column"
"github.com/pingcap/tidb/context"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/optimizer/plan"
"github.com/pingcap/tidb/parser/opcode"
"github.com/pingcap/tidb/sessionctx/autocommit"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/types"
)

Expand Down Expand Up @@ -83,6 +85,8 @@ func (b *executorBuilder) build(p plan.Plan) Executor {
return b.buildSelectLock(v)
case *plan.ShowDDL:
return b.buildShowDDL(v)
case *plan.Show:
return b.buildShow(v)
case *plan.Simple:
return b.buildSimple(v)
case *plan.Sort:
Expand Down Expand Up @@ -335,6 +339,26 @@ func (b *executorBuilder) buildDelete(v *plan.Delete) Executor {
}
}

func (b *executorBuilder) buildShow(v *plan.Show) Executor {
e := &ShowExec{
Tp: v.Tp,
DBName: model.NewCIStr(v.DBName),
Table: v.Table,
Column: v.Column,
User: v.User,
Flag: v.Flag,
Full: v.Full,
GlobalScope: v.GlobalScope,
ctx: b.ctx,
is: b.is,
fields: v.Fields(),
}
if e.Tp == ast.ShowGrants && len(e.User) == 0 {
e.User = variable.GetSessionVars(e.ctx).User
}
return e
}

func (b *executorBuilder) buildSimple(v *plan.Simple) Executor {
switch s := v.Statement.(type) {
case *ast.GrantStmt:
Expand Down
Loading

0 comments on commit 37585a0

Please sign in to comment.