Skip to content

Commit

Permalink
[release-20.0] bugfix: treat EXPLAIN like SELECT (#17054) (#17057)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
Co-authored-by: Andrés Taylor <andres@planetscale.com>
  • Loading branch information
vitess-bot[bot] and systay authored Oct 25, 2024
1 parent 6d2ef17 commit 2043068
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 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
2 changes: 1 addition & 1 deletion go/vt/vttablet/endtoend/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func TestPrepareRollback(t *testing.T) {
err = client.Prepare("aa")
if err != nil {
client.RollbackPrepared("aa", 0)
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
err = client.RollbackPrepared("aa", 0)
require.NoError(t, err)
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vttablet/tabletserver/planbuilder/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ 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, err = &Plan{PlanID: PlanOtherRead}, nil
// 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, err = &Plan{PlanID: PlanOtherAdmin}, nil
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 2043068

Please sign in to comment.