Skip to content

Commit

Permalink
added a fields len check in rename_fields engine to avoid renamefield…
Browse files Browse the repository at this point in the history
…s call

Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal authored and frouioui committed Sep 2, 2021
1 parent 59207f4 commit bcd3534
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ func TestRenameFieldsOnOLAP(t *testing.T) {
}()

qr := exec(t, conn, "show tables")
assert.Equal(t, `[[VARCHAR("aggr_test")] [VARCHAR("t1")] [VARCHAR("t1_id2_idx")] [VARCHAR("t2")] [VARCHAR("t2_id4_idx")] [VARCHAR("t3")] [VARCHAR("t3_id7_idx")] [VARCHAR("t4")] [VARCHAR("t4_id2_idx")] [VARCHAR("t5_null_vindex")] [VARCHAR("t6")] [VARCHAR("t6_id2_idx")] [VARCHAR("t7_fk")] [VARCHAR("t7_xxhash")] [VARCHAR("t7_xxhash_idx")] [VARCHAR("t8")] [VARCHAR("vstream_test")]]`, fmt.Sprintf("%v", qr.Rows))
require.Equal(t, 1, len(qr.Fields))
assert.Equal(t, `Tables_in_ks`, fmt.Sprintf("%v", qr.Fields[0].Name))
_ = exec(t, conn, "use mysql")
qr = exec(t, conn, "select @@workload")
assert.Equal(t, `[[VARBINARY("OLAP")]]`, fmt.Sprintf("%v", qr.Rows))
Expand Down
6 changes: 5 additions & 1 deletion go/vt/vtgate/engine/rename_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ func (r *RenameFields) StreamExecute(vcursor VCursor, bindVars map[string]*query
if wantfields {
innerCallback := callback
callback = func(result *sqltypes.Result) error {
r.renameFields(result)
// Only the first callback will contain the fields.
// This check is to avoid going over the RenameFields indices when no fields are present in the result set.
if len(result.Fields) != 0 {
r.renameFields(result)
}
return innerCallback(result)
}
}
Expand Down

0 comments on commit bcd3534

Please sign in to comment.