From 31edcf0b5e14d07627cc1ad79a4861459c831b05 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Mon, 14 Sep 2020 11:45:49 +0200 Subject: [PATCH 1/2] make sure dual queries set found_rows correctly Signed-off-by: Andres Taylor --- go/test/endtoend/vtgate/misc_test.go | 10 ++++++++++ go/vt/vtgate/engine/singlerow.go | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/go/test/endtoend/vtgate/misc_test.go b/go/test/endtoend/vtgate/misc_test.go index c0b2beed76b..ef5615527fd 100644 --- a/go/test/endtoend/vtgate/misc_test.go +++ b/go/test/endtoend/vtgate/misc_test.go @@ -345,6 +345,16 @@ func TestSwitchBetweenOlapAndOltp(t *testing.T) { exec(t, conn, "set workload='oltp'") } +func TestFoundRowsOnDualQueries(t *testing.T) { + ctx := context.Background() + conn, err := mysql.Connect(ctx, &vtParams) + require.NoError(t, err) + defer conn.Close() + + exec(t, conn, "select 42") + assertMatches(t, conn, "select found_rows()", "[[UINT64(1)]]") +} + func TestUseStmtInOLAP(t *testing.T) { defer cluster.PanicHandler(t) ctx := context.Background() diff --git a/go/vt/vtgate/engine/singlerow.go b/go/vt/vtgate/engine/singlerow.go index d7c2e1fefe4..260418705be 100644 --- a/go/vt/vtgate/engine/singlerow.go +++ b/go/vt/vtgate/engine/singlerow.go @@ -47,9 +47,7 @@ func (s *SingleRow) GetTableName() string { // Execute performs a non-streaming exec. func (s *SingleRow) Execute(vcursor VCursor, bindVars map[string]*query.BindVariable, wantfields bool) (*sqltypes.Result, error) { result := sqltypes.Result{ - Fields: nil, - RowsAffected: 0, - InsertID: 0, + RowsAffected: 1, Rows: [][]sqltypes.Value{ {}, }, @@ -60,9 +58,7 @@ func (s *SingleRow) Execute(vcursor VCursor, bindVars map[string]*query.BindVari // StreamExecute performs a streaming exec. func (s *SingleRow) StreamExecute(vcursor VCursor, bindVars map[string]*query.BindVariable, wantields bool, callback func(*sqltypes.Result) error) error { result := sqltypes.Result{ - Fields: nil, - RowsAffected: 0, - InsertID: 0, + RowsAffected: 1, Rows: [][]sqltypes.Value{ {}, }, From 5115f7affd1c4df69cb2eccce87903f9201695be Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Mon, 14 Sep 2020 14:30:06 +0200 Subject: [PATCH 2/2] update test expectations Signed-off-by: Andres Taylor --- go/vt/vtgate/executor_select_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index a0ffb4533ed..d88868f283f 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -303,6 +303,7 @@ func TestSelectLastInsertId(t *testing.T) { sql := "select last_insert_id()" result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) wantResult := &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "last_insert_id()", Type: sqltypes.Uint64}, }, @@ -324,6 +325,7 @@ func TestSelectUserDefindVariable(t *testing.T) { result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) require.NoError(t, err) wantResult := &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "@foo", Type: sqltypes.Null}, }, @@ -337,6 +339,7 @@ func TestSelectUserDefindVariable(t *testing.T) { result, err = executorExec(executor, sql, map[string]*querypb.BindVariable{}) require.NoError(t, err) wantResult = &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "@foo", Type: sqltypes.VarBinary}, }, @@ -360,11 +363,12 @@ func TestFoundRows(t *testing.T) { sql := "select found_rows()" result, err := executorExec(executor, sql, map[string]*querypb.BindVariable{}) wantResult := &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "found_rows()", Type: sqltypes.Uint64}, }, Rows: [][]sqltypes.Value{{ - sqltypes.NewUint64(0), + sqltypes.NewUint64(1), }}, } require.NoError(t, err) @@ -389,6 +393,7 @@ func TestRowCount(t *testing.T) { func testRowCount(t *testing.T, executor *Executor, wantRowCount int64) { result, err := executorExec(executor, "select row_count()", map[string]*querypb.BindVariable{}) wantResult := &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "row_count()", Type: sqltypes.Int64}, }, @@ -492,6 +497,7 @@ func TestSelectDatabase(t *testing.T) { sql, map[string]*querypb.BindVariable{}) wantResult := &sqltypes.Result{ + RowsAffected: 1, Fields: []*querypb.Field{ {Name: "database()", Type: sqltypes.VarBinary}, },