From 8e11b8acb5ab2af9c5ed96a6d2375eb32aa810a0 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 10 Sep 2020 11:44:29 +0200 Subject: [PATCH] allow StreamExecute with empty results Signed-off-by: Andres Taylor --- go/test/endtoend/vtgate/misc_test.go | 10 ++++++++++ go/vt/vtgate/executor.go | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/go/test/endtoend/vtgate/misc_test.go b/go/test/endtoend/vtgate/misc_test.go index 4e15153fc3b..53664b06f0b 100644 --- a/go/test/endtoend/vtgate/misc_test.go +++ b/go/test/endtoend/vtgate/misc_test.go @@ -335,6 +335,16 @@ func TestOffsetAndLimitWithOLAP(t *testing.T) { assertMatches(t, conn, "select id1 from t1 order by id1 limit 3 offset 2", "[[INT64(3)] [INT64(4)] [INT64(5)]]") } +func TestSwitchBetweenOlapAndOltp(t *testing.T) { + ctx := context.Background() + conn, err := mysql.Connect(ctx, &vtParams) + require.NoError(t, err) + defer conn.Close() + + exec(t, conn, "set workload='olap'") + exec(t, conn, "set workload='oltp'") +} + func assertMatches(t *testing.T, conn *mysql.Conn, query, expected string) { t.Helper() qr := exec(t, conn, query) diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 7a61721d49e..ab2ef1e757a 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -996,6 +996,7 @@ func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession // dictated by stream_buffer_size. result := &sqltypes.Result{} byteCount := 0 + seenResults := false err = plan.Instructions.StreamExecute(vcursor, bindVars, true, func(qr *sqltypes.Result) error { // If the row has field info, send it separately. // TODO(sougou): this behavior is for handling tests because @@ -1005,6 +1006,7 @@ func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession if err := callback(qrfield); err != nil { return err } + seenResults = true } for _, row := range qr.Rows { @@ -1015,6 +1017,7 @@ func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession if byteCount >= e.streamSize { err := callback(result) + seenResults = true result = &sqltypes.Result{} byteCount = 0 if err != nil { @@ -1026,7 +1029,7 @@ func (e *Executor) StreamExecute(ctx context.Context, method string, safeSession }) // Send left-over rows. - if len(result.Rows) > 0 { + if len(result.Rows) > 0 || !seenResults { if err := callback(result); err != nil { return err }