diff --git a/go/vt/vttablet/endtoend/queries_test.go b/go/vt/vttablet/endtoend/queries_test.go index 3dad415c1c1..b035013ecc3 100644 --- a/go/vt/vttablet/endtoend/queries_test.go +++ b/go/vt/vttablet/endtoend/queries_test.go @@ -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", diff --git a/go/vt/vttablet/tabletserver/planbuilder/plan.go b/go/vt/vttablet/tabletserver/planbuilder/plan.go index 7b1e57c2f90..10c37d979a8 100644 --- a/go/vt/vttablet/tabletserver/planbuilder/plan.go +++ b/go/vt/vttablet/tabletserver/planbuilder/plan.go @@ -234,7 +234,16 @@ func Build(env *vtenv.Environment, statement sqlparser.Statement, tables map[str case *sqlparser.Show: plan, err = analyzeShow(stmt, dbName) case *sqlparser.Analyze, sqlparser.Explain: +<<<<<<< HEAD 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), + } +>>>>>>> 11a655ca06 (bugfix: treat EXPLAIN like SELECT (#17054)) case *sqlparser.OtherAdmin: plan, err = &Plan{PlanID: PlanOtherAdmin}, nil case *sqlparser.Savepoint: diff --git a/go/vt/vttablet/tabletserver/planbuilder/testdata/exec_cases.txt b/go/vt/vttablet/tabletserver/planbuilder/testdata/exec_cases.txt index 977b3822050..d921180f158 100644 --- a/go/vt/vttablet/tabletserver/planbuilder/testdata/exec_cases.txt +++ b/go/vt/vttablet/tabletserver/planbuilder/testdata/exec_cases.txt @@ -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 @@ -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