diff --git a/go/vt/vttablet/endtoend/queries_test.go b/go/vt/vttablet/endtoend/queries_test.go index 5a57f681a10..f67d3219010 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/endtoend/transaction_test.go b/go/vt/vttablet/endtoend/transaction_test.go index b15e73585ba..b0580978b3c 100644 --- a/go/vt/vttablet/endtoend/transaction_test.go +++ b/go/vt/vttablet/endtoend/transaction_test.go @@ -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) diff --git a/go/vt/vttablet/tabletserver/planbuilder/plan.go b/go/vt/vttablet/tabletserver/planbuilder/plan.go index 7b1e57c2f90..d37896a84f9 100644 --- a/go/vt/vttablet/tabletserver/planbuilder/plan.go +++ b/go/vt/vttablet/tabletserver/planbuilder/plan.go @@ -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: 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