Skip to content
Merged
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
6 changes: 3 additions & 3 deletions go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,9 +1358,9 @@ func (e *Executor) getPlan(vcursor *vcursorImpl, sql string, comments sqlparser.
}

planHash := sha256.New()
planHash.Write([]byte(vcursor.planPrefixKey()))
planHash.Write([]byte{':'})
planHash.Write(hack.StringBytes(query))
_, _ = planHash.Write([]byte(vcursor.planPrefixKey()))
_, _ = planHash.Write([]byte{':'})
_, _ = planHash.Write(hack.StringBytes(query))
planKey := hex.EncodeToString(planHash.Sum(nil))

if plan, ok := e.plans.Get(planKey); ok {
Expand Down
27 changes: 26 additions & 1 deletion go/vt/vtgate/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,32 @@ func TestExecutorShow(t *testing.T) {
assert.EqualError(t, err, want, query)
}

func TestExecutorShowTargeted(t *testing.T) {
executor, _, sbc2, _ := createLegacyExecutorEnv()
session := NewSafeSession(&vtgatepb.Session{TargetString: "TestExecutor/40-60"})

queries := []string{
"show databases",
"show variables like 'read_only'",
"show collation",
"show collation where `Charset` = 'utf8' and `Collation` = 'utf8_bin'",
"show tables",
fmt.Sprintf("show tables from %v", KsTestUnsharded),
"show create table user_seq",
"show full columns from table1",
"show plugins",
"show warnings",
}

for _, sql := range queries {
_, err := executor.Execute(ctx, "TestExecutorShowTargeted", session, sql, nil)
require.NoError(t, err)
assert.NotZero(t, len(sbc2.Queries), "Tablet should have received 'show' query")
lastQuery := sbc2.Queries[len(sbc2.Queries)-1].Sql
assert.Equal(t, sql, lastQuery, "Got: %v, want %v", lastQuery, sql)
}
}

func TestExecutorUse(t *testing.T) {
executor, _, _, _ := createLegacyExecutorEnv()
session := NewSafeSession(&vtgatepb.Session{Autocommit: true, TargetString: "@primary"})
Expand Down Expand Up @@ -1056,7 +1082,6 @@ func TestExecutorOther(t *testing.T) {
}

stmts := []string{
"show tables",
"analyze table t1",
"describe select * from t1",
"explain select * from t1",
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func createInstructionFor(query string, stmt sqlparser.Statement, reservedVars *
// Empty by design. Not executed by a plan
return nil, nil
case *sqlparser.Show:
return buildShowPlan(stmt, vschema)
return buildRoutePlan(stmt, reservedVars, vschema, buildShowPlan)
case *sqlparser.LockTables:
return buildRoutePlan(stmt, reservedVars, vschema, buildLockPlan)
case *sqlparser.UnlockTables:
Expand Down
5 changes: 3 additions & 2 deletions go/vt/vtgate/planbuilder/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const (
charset = "charset"
)

func buildShowPlan(stmt *sqlparser.Show, vschema ContextVSchema) (engine.Primitive, error) {
switch show := stmt.Internal.(type) {
func buildShowPlan(stmt sqlparser.Statement, _ *sqlparser.ReservedVars, vschema ContextVSchema) (engine.Primitive, error) {
showStmt := stmt.(*sqlparser.Show)
switch show := showStmt.Internal.(type) {
case *sqlparser.ShowBasic:
return buildShowBasicPlan(show, vschema)
case *sqlparser.ShowCreate:
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/querylogz.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ func querylogzHandler(ch chan interface{}, w http.ResponseWriter, r *http.Reques
stats, ok := out.(*LogStats)
if !ok {
err := fmt.Errorf("unexpected value in %s: %#v (expecting value of type %T)", QueryLogger.Name(), out, &LogStats{})
io.WriteString(w, `<tr class="error">`)
io.WriteString(w, err.Error())
io.WriteString(w, "</tr>")
_, _ = io.WriteString(w, `<tr class="error">`)
_, _ = io.WriteString(w, err.Error())
_, _ = io.WriteString(w, "</tr>")
log.Error(err)
continue
}
Expand Down