Remove SQL EXPLAIN command

This commit is contained in:
Tobie Morgan Hitchcock 2016-09-21 00:34:21 +01:00
parent bde073cd36
commit f37ec653d1
28 changed files with 44 additions and 175 deletions

View file

@ -26,10 +26,6 @@ func executeCreateStatement(txn kvs.TX, ast *sql.CreateStatement) (out []interfa
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -26,10 +26,6 @@ func executeDefineTableStatement(txn kvs.TX, ast *sql.DefineTableStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -67,10 +63,6 @@ func executeDefineRulesStatement(txn kvs.TX, ast *sql.DefineRulesStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -118,10 +110,6 @@ func executeDefineFieldStatement(txn kvs.TX, ast *sql.DefineFieldStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -165,10 +153,6 @@ func executeDefineIndexStatement(txn kvs.TX, ast *sql.DefineIndexStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -25,10 +25,6 @@ func executeDeleteStatement(txn kvs.TX, ast *sql.DeleteStatement) (out []interfa
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -25,10 +25,6 @@ import (
func executeInfoStatement(txn kvs.TX, ast *sql.InfoStatement) (out []interface{}, err error) {
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
txn, err = db.Txn(false)
if err != nil {

View file

@ -25,10 +25,6 @@ func executeModifyStatement(txn kvs.TX, ast *sql.ModifyStatement) (out []interfa
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -24,10 +24,6 @@ func executeRemoveTableStatement(txn kvs.TX, ast *sql.RemoveTableStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -83,10 +79,6 @@ func executeRemoveRulesStatement(txn kvs.TX, ast *sql.RemoveRulesStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -122,10 +114,6 @@ func executeRemoveFieldStatement(txn kvs.TX, ast *sql.RemoveFieldStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)
@ -157,10 +145,6 @@ func executeRemoveIndexStatement(txn kvs.TX, ast *sql.RemoveIndexStatement) (out
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -23,10 +23,6 @@ import (
func executeSelectStatement(txn kvs.TX, ast *sql.SelectStatement) (out []interface{}, err error) {
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
txn, err = db.Txn(false)
if err != nil {

View file

@ -25,10 +25,6 @@ func executeUpdateStatement(txn kvs.TX, ast *sql.UpdateStatement) (out []interfa
var local bool
if ast.EX {
return append(out, ast), nil
}
if txn == nil {
local = true
txn, err = db.Txn(true)

View file

@ -64,7 +64,6 @@ type UseStatement struct {
// InfoStatement represents an SQL INFO statement.
type InfoStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -77,7 +76,6 @@ type InfoStatement struct {
// SelectStatement represents a SQL SELECT statement.
type SelectStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -94,7 +92,6 @@ type SelectStatement struct {
// CreateStatement represents a SQL CREATE statement.
type CreateStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -105,7 +102,6 @@ type CreateStatement struct {
// UpdateStatement represents a SQL UPDATE statement.
type UpdateStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -117,7 +113,6 @@ type UpdateStatement struct {
// ModifyStatement represents a SQL MODIFY statement.
type ModifyStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -129,7 +124,6 @@ type ModifyStatement struct {
// DeleteStatement represents a SQL DELETE statement.
type DeleteStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -141,7 +135,6 @@ type DeleteStatement struct {
// RelateStatement represents a SQL RELATE statement.
type RelateStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -154,7 +147,6 @@ type RelateStatement struct {
// RecordStatement represents a SQL RECORD statement.
type RecordStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -170,7 +162,6 @@ type RecordStatement struct {
// DefineTableStatement represents an SQL DEFINE TABLE statement.
type DefineTableStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -179,7 +170,6 @@ type DefineTableStatement struct {
// RemoveTableStatement represents an SQL REMOVE TABLE statement.
type RemoveTableStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -192,7 +182,6 @@ type RemoveTableStatement struct {
// DefineRulesStatement represents an SQL DEFINE RULES statement.
type DefineRulesStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -204,7 +193,6 @@ type DefineRulesStatement struct {
// RemoveRulesStatement represents an SQL REMOVE RULES statement.
type RemoveRulesStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -218,7 +206,6 @@ type RemoveRulesStatement struct {
// DefineFieldStatement represents an SQL DEFINE FIELD statement.
type DefineFieldStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -239,7 +226,6 @@ type DefineFieldStatement struct {
// RemoveFieldStatement represents an SQL REMOVE FIELD statement.
type RemoveFieldStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -253,7 +239,6 @@ type RemoveFieldStatement struct {
// DefineIndexStatement represents an SQL DEFINE INDEX statement.
type DefineIndexStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`
@ -265,7 +250,6 @@ type DefineIndexStatement struct {
// RemoveIndexStatement represents an SQL REMOVE INDEX statement.
type RemoveIndexStatement struct {
EX bool `codec:"-"`
KV string `codec:"-"`
NS string `codec:"-"`
DB string `codec:"-"`

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseCreateStatement(explain bool) (stmt *CreateStatement, err error) {
func (p *parser) parseCreateStatement() (stmt *CreateStatement, err error) {
stmt = &CreateStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,20 +14,20 @@
package sql
func (p *parser) parseDefineStatement(explain bool) (Statement, error) {
func (p *parser) parseDefineStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(TABLE, RULES, FIELD, INDEX)
switch tok {
case TABLE:
return p.parseDefineTableStatement(explain)
return p.parseDefineTableStatement()
case RULES:
return p.parseDefineRulesStatement(explain)
return p.parseDefineRulesStatement()
case FIELD:
return p.parseDefineFieldStatement(explain)
return p.parseDefineFieldStatement()
case INDEX:
return p.parseDefineIndexStatement(explain)
return p.parseDefineIndexStatement()
default:
return nil, err
}

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseDeleteStatement(explain bool) (stmt *DeleteStatement, err error) {
func (p *parser) parseDeleteStatement() (stmt *DeleteStatement, err error) {
stmt = &DeleteStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldStatement, err error) {
func (p *parser) parseDefineFieldStatement() (stmt *DefineFieldStatement, err error) {
stmt = &DefineFieldStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
@ -135,12 +133,10 @@ func (p *parser) parseDefineFieldStatement(explain bool) (stmt *DefineFieldState
}
func (p *parser) parseRemoveFieldStatement(explain bool) (stmt *RemoveFieldStatement, err error) {
func (p *parser) parseRemoveFieldStatement() (stmt *RemoveFieldStatement, err error) {
stmt = &RemoveFieldStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexStatement, err error) {
func (p *parser) parseDefineIndexStatement() (stmt *DefineIndexStatement, err error) {
stmt = &DefineIndexStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
@ -54,12 +52,10 @@ func (p *parser) parseDefineIndexStatement(explain bool) (stmt *DefineIndexState
}
func (p *parser) parseRemoveIndexStatement(explain bool) (stmt *RemoveIndexStatement, err error) {
func (p *parser) parseRemoveIndexStatement() (stmt *RemoveIndexStatement, err error) {
stmt = &RemoveIndexStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseInfoStatement(explain bool) (stmt *InfoStatement, err error) {
func (p *parser) parseInfoStatement() (stmt *InfoStatement, err error) {
stmt = &InfoStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseModifyStatement(explain bool) (stmt *ModifyStatement, err error) {
func (p *parser) parseModifyStatement() (stmt *ModifyStatement, err error) {
stmt = &ModifyStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -115,48 +115,42 @@ func (p *parser) parseMulti() (*Query, error) {
// parseSingle parses a single SQL SELECT statement.
func (p *parser) parseSingle() (Statement, error) {
var explain bool
if _, _, exi := p.mightBe(EXPLAIN); exi {
explain = true
}
tok, _, err := p.shouldBe(USE, INFO, LET, BEGIN, CANCEL, COMMIT, ROLLBACK, SELECT, CREATE, UPDATE, INSERT, UPSERT, MODIFY, DELETE, RELATE, RECORD, DEFINE, REMOVE)
switch tok {
case USE:
return p.parseUseStatement(explain)
return p.parseUseStatement()
case INFO:
return p.parseInfoStatement(explain)
return p.parseInfoStatement()
case BEGIN:
return p.parseBeginStatement(explain)
return p.parseBeginStatement()
case CANCEL, ROLLBACK:
return p.parseCancelStatement(explain)
return p.parseCancelStatement()
case COMMIT:
return p.parseCommitStatement(explain)
return p.parseCommitStatement()
case SELECT:
return p.parseSelectStatement(explain)
return p.parseSelectStatement()
case CREATE, INSERT:
return p.parseCreateStatement(explain)
return p.parseCreateStatement()
case UPDATE, UPSERT:
return p.parseUpdateStatement(explain)
return p.parseUpdateStatement()
case MODIFY:
return p.parseModifyStatement(explain)
return p.parseModifyStatement()
case DELETE:
return p.parseDeleteStatement(explain)
return p.parseDeleteStatement()
case RELATE:
return p.parseRelateStatement(explain)
return p.parseRelateStatement()
case RECORD:
return p.parseRecordStatement(explain)
return p.parseRecordStatement()
case DEFINE:
return p.parseDefineStatement(explain)
return p.parseDefineStatement()
case REMOVE:
return p.parseRemoveStatement(explain)
return p.parseRemoveStatement()
default:
return nil, err

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseRecordStatement(explain bool) (stmt *RecordStatement, err error) {
func (p *parser) parseRecordStatement() (stmt *RecordStatement, err error) {
stmt = &RecordStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseRelateStatement(explain bool) (stmt *RelateStatement, err error) {
func (p *parser) parseRelateStatement() (stmt *RelateStatement, err error) {
stmt = &RelateStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,20 +14,20 @@
package sql
func (p *parser) parseRemoveStatement(explain bool) (Statement, error) {
func (p *parser) parseRemoveStatement() (Statement, error) {
// Inspect the next token.
tok, _, err := p.shouldBe(TABLE, RULES, FIELD, INDEX)
switch tok {
case TABLE:
return p.parseRemoveTableStatement(explain)
return p.parseRemoveTableStatement()
case RULES:
return p.parseRemoveRulesStatement(explain)
return p.parseRemoveRulesStatement()
case FIELD:
return p.parseRemoveFieldStatement(explain)
return p.parseRemoveFieldStatement()
case INDEX:
return p.parseRemoveIndexStatement(explain)
return p.parseRemoveIndexStatement()
default:
return nil, err
}

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesStatement, err error) {
func (p *parser) parseDefineRulesStatement() (stmt *DefineRulesStatement, err error) {
stmt = &DefineRulesStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
@ -77,12 +75,10 @@ func (p *parser) parseDefineRulesStatement(explain bool) (stmt *DefineRulesState
}
func (p *parser) parseRemoveRulesStatement(explain bool) (stmt *RemoveRulesStatement, err error) {
func (p *parser) parseRemoveRulesStatement() (stmt *RemoveRulesStatement, err error) {
stmt = &RemoveRulesStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseSelectStatement(explain bool) (stmt *SelectStatement, err error) {
func (p *parser) parseSelectStatement() (stmt *SelectStatement, err error) {
stmt = &SelectStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -249,25 +249,6 @@ func Test_Parse_Queries_Use(t *testing.T) {
}
func Test_Parse_Queries_Explain(t *testing.T) {
var tests = []tester{
{
sql: `EXPLAIN SELECT ALL FROM person`,
res: &Query{Statements: []Statement{&SelectStatement{
EX: true,
Expr: []*Field{{Expr: &All{}, Alias: "ALL"}},
What: []Expr{&Table{"person"}},
}}},
},
}
for _, test := range tests {
testsql(t, test)
}
}
func Test_Parse_Queries_Select(t *testing.T) {
date, _ := time.Parse("2006-01-02", "1987-06-22")

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseDefineTableStatement(explain bool) (stmt *DefineTableStatement, err error) {
func (p *parser) parseDefineTableStatement() (stmt *DefineTableStatement, err error) {
stmt = &DefineTableStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)
@ -36,12 +34,10 @@ func (p *parser) parseDefineTableStatement(explain bool) (stmt *DefineTableState
}
func (p *parser) parseRemoveTableStatement(explain bool) (stmt *RemoveTableStatement, err error) {
func (p *parser) parseRemoveTableStatement() (stmt *RemoveTableStatement, err error) {
stmt = &RemoveTableStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -124,7 +124,6 @@ const (
DISTINCT
EMPTY
ENUM
EXPLAIN
EXPUNGE
FALSE
FIELD
@ -284,7 +283,6 @@ var tokens = [...]string{
DISTINCT: "DISTINCT",
EMPTY: "EMPTY",
ENUM: "ENUM",
EXPLAIN: "EXPLAIN",
EXPUNGE: "EXPUNGE",
FALSE: "FALSE",
FIELD: "FIELD",

View file

@ -14,7 +14,7 @@
package sql
func (p *parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err error) {
func (p *parser) parseBeginStatement() (stmt *BeginStatement, err error) {
stmt = &BeginStatement{}
@ -28,7 +28,7 @@ func (p *parser) parseBeginStatement(explain bool) (stmt *BeginStatement, err er
}
func (p *parser) parseCancelStatement(explain bool) (stmt *CancelStatement, err error) {
func (p *parser) parseCancelStatement() (stmt *CancelStatement, err error) {
stmt = &CancelStatement{}
@ -42,7 +42,7 @@ func (p *parser) parseCancelStatement(explain bool) (stmt *CancelStatement, err
}
func (p *parser) parseCommitStatement(explain bool) (stmt *CommitStatement, err error) {
func (p *parser) parseCommitStatement() (stmt *CommitStatement, err error) {
stmt = &CommitStatement{}

View file

@ -14,12 +14,10 @@
package sql
func (p *parser) parseUpdateStatement(explain bool) (stmt *UpdateStatement, err error) {
func (p *parser) parseUpdateStatement() (stmt *UpdateStatement, err error) {
stmt = &UpdateStatement{}
stmt.EX = explain
stmt.KV = p.c.Get("KV").(string)
stmt.NS = p.c.Get("NS").(string)
stmt.DB = p.c.Get("DB").(string)

View file

@ -14,7 +14,7 @@
package sql
func (p *parser) parseUseStatement(explain bool) (stmt *UseStatement, err error) {
func (p *parser) parseUseStatement() (stmt *UseStatement, err error) {
stmt = &UseStatement{}