Skip to content

Commit

Permalink
simplified opt code instead of using AST
Browse files Browse the repository at this point in the history
Signed-off-by: Akilan Selvacoumar <[email protected]>

Signed-off-by:  <[email protected]>
  • Loading branch information
Akilan1999 committed Feb 18, 2021
1 parent af84bae commit 4cd2a7a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 71 deletions.
3 changes: 0 additions & 3 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type (
SetLimit(*Limit)
SetLock(lock Lock)
MakeDistinct()
ContainsOnlyInformationSchema() bool
}

// DDLStatement represents any DDL Statement
Expand Down Expand Up @@ -1447,7 +1446,6 @@ type (
// TableExpr represents a table expression.
TableExpr interface {
iTableExpr()
ContainsOnlyInformationSchema() bool
SQLNode
}

Expand Down Expand Up @@ -1486,7 +1484,6 @@ type (
// SimpleTableExpr represents a simple table expression.
SimpleTableExpr interface {
iSimpleTableExpr()
ContainsOnlyInformationSchema() bool
SQLNode
}

Expand Down
64 changes: 0 additions & 64 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,52 +771,6 @@ func (node *Select) MakeDistinct() {
node.Distinct = true
}

// ContainsOnlyInformationSchema returns if the select statement only contains information_schema tables
func (node *Select) ContainsOnlyInformationSchema() bool {
for _, expr := range node.From {
if !expr.ContainsOnlyInformationSchema() {
return false
}
}
return true
}

// ContainsOnlyInformationSchema returns if the expression only contains information_schema tables
func (expr *ParenTableExpr) ContainsOnlyInformationSchema() bool {
for _, tableExpr := range expr.Exprs {
if !tableExpr.ContainsOnlyInformationSchema() {
return false
}
}
return true
}

// ContainsOnlyInformationSchema returns if the expression only contains information_schema tables
func (expr *JoinTableExpr) ContainsOnlyInformationSchema() bool {
if !expr.LeftExpr.ContainsOnlyInformationSchema() {
return false
}
if !expr.RightExpr.ContainsOnlyInformationSchema() {
return false
}
return true
}

// ContainsOnlyInformationSchema returns if the expression only contains information_schema tables
func (node *AliasedTableExpr) ContainsOnlyInformationSchema() bool {
return node.Expr.ContainsOnlyInformationSchema()
}

// ContainsOnlyInformationSchema returns if the table is from information_schema
func (node *DerivedTable) ContainsOnlyInformationSchema() bool {
return node.Select.ContainsOnlyInformationSchema()
}

// ContainsOnlyInformationSchema returns if the table is from information_schema
func (node TableName) ContainsOnlyInformationSchema() bool {
return strings.ToLower(node.Qualifier.String()) == "information_schema"
}

// AddWhere adds the boolean expression to the
// WHERE clause as an AND condition.
func (node *Select) AddWhere(expr Expr) {
Expand Down Expand Up @@ -869,11 +823,6 @@ func (node *ParenSelect) MakeDistinct() {
node.Select.MakeDistinct()
}

// ContainsOnlyInformationSchema returns if the select statement only contains information_schema tables
func (node *ParenSelect) ContainsOnlyInformationSchema() bool {
return node.Select.ContainsOnlyInformationSchema()
}

// AddWhere adds the boolean expression to the
// WHERE clause as an AND condition.
func (node *Update) AddWhere(expr Expr) {
Expand Down Expand Up @@ -910,19 +859,6 @@ func (node *Union) MakeDistinct() {
node.UnionSelects[len(node.UnionSelects)-1].Distinct = true
}

// ContainsOnlyInformationSchema returns if the union statement only contains information_schema tables
func (node *Union) ContainsOnlyInformationSchema() bool {
if !node.FirstStatement.ContainsOnlyInformationSchema() {
return false
}
for _, unionSelect := range node.UnionSelects {
if !unionSelect.Statement.ContainsOnlyInformationSchema() {
return false
}
}
return true
}

//Unionize returns a UNION, either creating one or adding SELECT to an existing one
func Unionize(lhs, rhs SelectStatement, distinct bool, by OrderBy, limit *Limit, lock Lock) *Union {
union, isUnion := lhs.(*Union)
Expand Down
4 changes: 2 additions & 2 deletions go/vt/sqlparser/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,5 +836,5 @@ func queryTimeout(d sqlparser.CommentDirectives) int {

// ContainsOnlyInformationSchema returns if the route only contains information_schema tables
func (rb *route) ContainsOnlyInformationSchema() bool {
return rb.Select.ContainsOnlyInformationSchema()
return rb.eroute.Opcode == engine.SelectDBA
}

0 comments on commit 4cd2a7a

Please sign in to comment.