Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-21.0] bugfix: treat EXPLAIN like SELECT (#17054) #17058

Open
wants to merge 1 commit into
base: release-21.0
Choose a base branch
from
Open
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
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
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
Loading