Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -4144,6 +4144,8 @@ type Explain struct {
Analyze bool
}

var _ WalkableSQLNode = &Explain{}

// Format formats the node.
func (node *Explain) Format(buf *TrackedBuffer) {
analyzeOpt := ""
Expand All @@ -4161,6 +4163,10 @@ func (node *Explain) Format(buf *TrackedBuffer) {
buf.Myprintf("explain %s%s%s%v", analyzeOpt, formatOpt, planOpt, node.Statement)
}

func (node *Explain) walkSubtree(visit Visit) error {
return Walk(visit, node.Statement)
}

const (
CreateTriggerStr = "create trigger"
CreateProcedureStr = "create procedure"
Expand Down
16 changes: 16 additions & 0 deletions go/vt/sqlparser/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ func TestInsertOnDupWhereFormatAndWalk(t *testing.T) {
require.True(t, visitedPredicate)
}

func TestInputExpressionInExplain(t *testing.T) {
stmt, err := Parse("explain select (select 1)")
require.NoError(t, err)
var inputExpression string
require.NoError(t, Walk(func(node SQLNode) (bool, error) {
if ae, ok := node.(*AliasedExpr); ok {
if _, ok := ae.Expr.(*Subquery); ok {
inputExpression = ae.InputExpression
return false, nil
}
}
return true, nil
}, stmt))
require.Equal(t, inputExpression, "(select 1)")
}

func TestRemoveHints(t *testing.T) {
for _, query := range []string{
"select * from t use index (i)",
Expand Down
Loading