Skip to content

Commit

Permalink
bugfix: treat EXPLAIN like SELECT (#17054)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay authored Oct 23, 2024
1 parent b0b7981 commit 11a655c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
14 changes: 14 additions & 0 deletions go/vt/vttablet/endtoend/queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ var TestQueryCases = []framework.Testable{
},
RowsReturned: 1,
},
&framework.TestCase{
Name: "explain with bindvars",
Query: "explain select :__vtudvp as `@p` from dual",
BindVars: map[string]*querypb.BindVariable{
"__vtudvp": sqltypes.Int64BindVariable(1),
},
Result: [][]string{
{"1", "SIMPLE", "", "", "", "", "", "", "", "", "", "No tables used"},
},
Rewritten: []string{
"explain select 1 as `@p` from dual",
},
RowsReturned: 1,
},
&framework.TestCase{
Name: "limit",
Query: "select /* limit */ eid, id from vitess_a limit :a",
Expand Down
7 changes: 6 additions & 1 deletion go/vt/vttablet/tabletserver/planbuilder/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ func Build(env *vtenv.Environment, statement sqlparser.Statement, tables map[str
case *sqlparser.Show:
plan, err = analyzeShow(stmt, dbName)
case *sqlparser.Analyze, sqlparser.Explain:
plan = &Plan{PlanID: PlanOtherRead}
// Analyze and Explain are treated as read-only queries.
// We send down a string, and get a table result back.
plan = &Plan{
PlanID: PlanSelect,
FullQuery: GenerateFullQuery(stmt),
}
case *sqlparser.OtherAdmin:
plan = &Plan{PlanID: PlanOtherAdmin}
case *sqlparser.Savepoint:
Expand Down
23 changes: 13 additions & 10 deletions go/vt/vttablet/tabletserver/planbuilder/testdata/exec_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,15 @@ options:PassthroughDMLs
# analyze
"analyze table a"
{
"PlanID": "OtherRead",
"PlanID": "Select",
"TableName": "",
"Permissions": [
{
"TableName": "a",
"Role": 1
}
]
{
"TableName": "a",
"Role": 1
}
],
"FullQuery": "analyze table a"
}

# show
Expand All @@ -783,15 +784,17 @@ options:PassthroughDMLs
# describe
"describe a"
{
"PlanID": "OtherRead",
"TableName": ""
"PlanID": "Select",
"TableName": "",
"FullQuery": "explain a"
}

# explain
"explain a"
{
"PlanID": "OtherRead",
"TableName": ""
"PlanID": "Select",
"TableName": "",
"FullQuery": "explain a"
}

# repair
Expand Down

0 comments on commit 11a655c

Please sign in to comment.