Skip to content

Commit

Permalink
Merge pull request #7475 from planetscale/show-plan
Browse files Browse the repository at this point in the history
Moving Show plan from executor to planbuilder
  • Loading branch information
harshit-gangal authored Feb 21, 2021
2 parents 02376a3 + 742c5f9 commit 0dbe96e
Show file tree
Hide file tree
Showing 52 changed files with 7,634 additions and 6,331 deletions.
61 changes: 25 additions & 36 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,34 +1208,28 @@ type (
ShowCollationFilterOpt Expr
}

// ShowColumns is of ShowInternal type, holds the show columns statement.
ShowColumns struct {
Full string
Table TableName
DbName string
Filter *ShowFilter
}

// ShowTableStatus is of ShowInternal type, holds SHOW TABLE STATUS queries.
ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
}

// ShowCommandType represents the show statement type.
ShowCommandType int8

// ShowBasic is of ShowInternal type, holds Simple SHOW queries with a filter.
ShowBasic struct {
Command ShowCommandType
Full bool
Tbl TableName
DbName string
Filter *ShowFilter
}

// ShowCreate is of ShowInternal type, holds SHOW CREATE queries.
ShowCreate struct {
Command ShowCommandType
Op TableName
}
)

func (*ShowLegacy) isShowInternal() {}
func (*ShowColumns) isShowInternal() {}
func (*ShowTableStatus) isShowInternal() {}
func (*ShowBasic) isShowInternal() {}
func (*ShowLegacy) isShowInternal() {}
func (*ShowBasic) isShowInternal() {}
func (*ShowCreate) isShowInternal() {}

// InsertRows represents the rows for an INSERT statement.
type InsertRows interface {
Expand Down Expand Up @@ -2442,17 +2436,6 @@ func (node *Show) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%v", node.Internal)
}

// Format formats the node.
func (node *ShowColumns) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show %s", node.Full)
buf.astPrintf(node, "columns from %v", node.Table)

buf.printIf(node.DbName != "", " from "+node.DbName)
if node.Filter != nil {
buf.astPrintf(node, "%v", node.Filter)
}
}

// Format formats the node.
func (node *ShowLegacy) Format(buf *TrackedBuffer) {
nodeType := strings.ToLower(node.Type)
Expand Down Expand Up @@ -3147,18 +3130,24 @@ func (node *Load) Format(buf *TrackedBuffer) {
}

// Format formats the node.
func (node *ShowTableStatus) Format(buf *TrackedBuffer) {
buf.WriteString("show table status")
if node.DatabaseName != "" {
buf.WriteString(" from ")
buf.WriteString(node.DatabaseName)
func (node *ShowBasic) Format(buf *TrackedBuffer) {
buf.WriteString("show")
if node.Full {
buf.WriteString(" full")
}
buf.astPrintf(node, "%s", node.Command.ToString())
if !node.Tbl.IsEmpty() {
buf.astPrintf(node, " from %v", node.Tbl)
}
if node.DbName != "" {
buf.astPrintf(node, " from %s", node.DbName)
}
buf.astPrintf(node, "%v", node.Filter)
}

// Format formats the node.
func (node *ShowBasic) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show%s%v", node.Command.ToString(), node.Filter)
func (node *ShowCreate) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show%s %v", node.Command.ToString(), node.Op)
}

// Format formats the node.
Expand Down
33 changes: 32 additions & 1 deletion go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1227,26 +1227,57 @@ func (ty ShowCommandType) ToString() string {
return CharsetStr
case Collation:
return CollationStr
case Column:
return ColumnStr
case CreateDb:
return CreateDbStr
case CreateE:
return CreateEStr
case CreateF:
return CreateFStr
case CreateProc:
return CreateProcStr
case CreateTbl:
return CreateTblStr
case CreateTr:
return CreateTrStr
case CreateV:
return CreateVStr
case Database:
return DatabaseStr
case FunctionC:
return FunctionCStr
case Function:
return FunctionStr
case Index:
return IndexStr
case OpenTable:
return OpenTableStr
case Privilege:
return PrivilegeStr
case ProcedureC:
return ProcedureCStr
case Procedure:
return ProcedureStr
case StatusGlobal:
return StatusGlobalStr
case StatusSession:
return StatusSessionStr
case Table:
return TableStr
case TableStatus:
return TableStatusStr
case Trigger:
return TriggerStr
case VariableGlobal:
return VariableGlobalStr
case VariableSession:
return VariableSessionStr
case Keyspace:
return KeyspaceStr
default:
return "Unknown ShowCommandType"
return "" +
"Unknown ShowCommandType"
}
}

Expand Down
31 changes: 31 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

package sqlparser

// String constants to be used in ast.
const (
// Select.Distinct
DistinctStr = "distinct "
Expand Down Expand Up @@ -211,12 +212,27 @@ const (
// ShowCommand Types
CharsetStr = " charset"
CollationStr = " collation"
ColumnStr = " columns"
CreateDbStr = " create database"
CreateEStr = " create event"
CreateFStr = " create function"
CreateProcStr = " create procedure"
CreateTblStr = " create table"
CreateTrStr = " create trigger"
CreateVStr = " create view"
DatabaseStr = " databases"
FunctionCStr = " function code"
FunctionStr = " function status"
IndexStr = " indexes"
OpenTableStr = " open tables"
PrivilegeStr = " privileges"
ProcedureCStr = " procedure code"
ProcedureStr = " procedure status"
StatusGlobalStr = " global status"
StatusSessionStr = " status"
TableStr = " tables"
TableStatusStr = " table status"
TriggerStr = " triggers"
VariableGlobalStr = " global variables"
VariableSessionStr = " variables"
KeyspaceStr = " keyspaces"
Expand Down Expand Up @@ -451,12 +467,27 @@ const (
UnknownCommandType ShowCommandType = iota
Charset
Collation
Column
CreateDb
CreateE
CreateF
CreateProc
CreateTbl
CreateTr
CreateV
Database
FunctionC
Function
Index
OpenTable
Privilege
ProcedureC
Procedure
StatusGlobal
StatusSession
Table
TableStatus
Trigger
VariableGlobal
VariableSession
Keyspace
Expand Down
10 changes: 8 additions & 2 deletions go/vt/sqlparser/parse_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func ParseTable(input string) (keyspace, table string, err error) {
case ID:
table = string(value)
default:
return "", "", vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid table name: %s", input)
table = KeywordString(token)
if table == "" {
return "", "", vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid table name: %s", input)
}
}

// Seen first ID, want '.' or 0
Expand All @@ -52,7 +55,10 @@ func ParseTable(input string) (keyspace, table string, err error) {
case ID:
table = string(value)
default:
return "", "", vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid table name: %s", input)
table = KeywordString(token)
if table == "" {
return "", "", vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid table name: %s", input)
}
}

// Seen second ID, want 0
Expand Down
45 changes: 20 additions & 25 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ var (
}, {
input: "insert /* bool expression on duplicate */ into a values (1, 2) on duplicate key update b = func(a), c = a > d",
}, {
input: "insert into user(username, `status`) values ('Chuck', default(`status`))",
input: "insert into `user`(username, `status`) values ('Chuck', default(`status`))",
}, {
input: "insert into user(format, tree, vitess) values ('Chuck', 42, 'Barry')",
output: "insert into user(`format`, `tree`, `vitess`) values ('Chuck', 42, 'Barry')",
output: "insert into `user`(`format`, `tree`, `vitess`) values ('Chuck', 42, 'Barry')",
}, {
input: "insert into customer () values ()",
output: "insert into customer values ()",
Expand Down Expand Up @@ -1182,7 +1182,7 @@ var (
output: "alter vschema on a add vindex hash (id) using hash",
}, {
input: "alter vschema on user add vindex name_lookup_vdx (name) using lookup_hash with owner=user, table=name_user_idx, from=name, to=user_id",
output: "alter vschema on user add vindex name_lookup_vdx (`name`) using lookup_hash with owner=user, table=name_user_idx, from=name, to=user_id",
output: "alter vschema on `user` add vindex name_lookup_vdx (`name`) using lookup_hash with owner=user, table=name_user_idx, from=name, to=user_id",
}, {
input: "alter vschema on user2 add vindex name_lastname_lookup_vdx (name,lastname) using lookup with owner=`user`, table=`name_lastname_keyspace_id_map`, from=`name,lastname`, to=`keyspace_id`",
output: "alter vschema on user2 add vindex name_lastname_lookup_vdx (`name`, lastname) using lookup with owner=user, table=name_lastname_keyspace_id_map, from=name,lastname, to=keyspace_id",
Expand Down Expand Up @@ -1325,28 +1325,22 @@ var (
input: "show collation where `Charset` = 'utf8' and `Collation` = 'utf8_bin'",
output: "show collation where `Charset` = 'utf8' and `Collation` = 'utf8_bin'",
}, {
input: "show create database d",
output: "show create database",
input: "show create database d",
}, {
input: "show create event e",
output: "show create event",
input: "show create event e",
}, {
input: "show create function f",
}, {
input: "show create procedure p",
output: "show create procedure",
input: "show create procedure p",
}, {
input: "show create table t",
output: "show create table t",
input: "show create table t",
}, {
input: "show create trigger t",
output: "show create trigger",
input: "show create trigger t",
}, {
input: "show create user u",
output: "show create user",
}, {
input: "show create view v",
output: "show create view",
input: "show create view v",
}, {
input: "show databases",
output: "show databases",
Expand Down Expand Up @@ -1379,17 +1373,18 @@ var (
input: "show grants for 'root@localhost'",
output: "show grants",
}, {
input: "show index from t",
input: "show index from t",
output: "show indexes from t",
}, {
input: "show indexes from t",
}, {
input: "show keys from t",
input: "show keys from t",
output: "show indexes from t",
}, {
input: "show master status",
output: "show master",
}, {
input: "show open tables",
output: "show open",
input: "show open tables",
}, {
input: "show plugins",
output: "show plugins",
Expand Down Expand Up @@ -1789,22 +1784,22 @@ var (
output: "show full columns from AO_E8B6CC_ISSUE_MAPPING from jiradb like '%'",
}, {
input: "SHOW KEYS FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show keys from AO_E8B6CC_ISSUE_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW CREATE TABLE `jiradb`.`AO_E8B6CC_ISSUE_MAPPING`",
output: "show create table jiradb.AO_E8B6CC_ISSUE_MAPPING",
}, {
input: "SHOW INDEX FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show index from AO_E8B6CC_ISSUE_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW FULL TABLES FROM `jiradb` LIKE '%'",
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW EXTENDED INDEX FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show extended index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED KEYS FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show extended keys from AO_E8B6CC_ISSUE_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW CREATE TABLE `jiradb`.`AO_E8B6CC_ISSUE_MAPPING`",
output: "show create table jiradb.AO_E8B6CC_ISSUE_MAPPING",
Expand All @@ -1828,10 +1823,10 @@ var (
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW EXTENDED INDEXES FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED INDEXES IN `AO_E8B6CC_PROJECT_MAPPING` IN `jiradb`",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
output: "show indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "do 1",
output: "otheradmin",
Expand Down
Loading

0 comments on commit 0dbe96e

Please sign in to comment.