Skip to content

Commit

Permalink
result append: remove the short circuit code
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Dec 18, 2024
1 parent 69175c3 commit 6c1a3d2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
9 changes: 3 additions & 6 deletions go/sqltypes/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,14 @@ func (result *Result) StripMetadata(incl querypb.ExecuteOptions_IncludedFields)
// to another result.Note currently it doesn't handle cases like
// if two results have different fields.We will enhance this function.
func (result *Result) AppendResult(src *Result) {
if src.RowsAffected == 0 && len(src.Rows) == 0 && len(src.Fields) == 0 {
return
}
if result.Fields == nil {
result.Fields = src.Fields
}
result.RowsAffected += src.RowsAffected
if src.InsertID != 0 || src.InsertIDChanged {
result.InsertID = src.InsertID
}
result.InsertIDChanged = result.InsertIDChanged || src.InsertIDChanged
if result.Fields == nil {
result.Fields = src.Fields
}
result.Rows = append(result.Rows, src.Rows...)
}

Expand Down
7 changes: 7 additions & 0 deletions go/test/endtoend/utils/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,10 @@ func (mcmp *MySQLCompare) ExecAllowError(query string) (*sqltypes.Result, error)
}
return vtQr, vtErr
}

func (mcmp *MySQLCompare) VExplain(query string) {
mcmp.t.Helper()
vtQr, vtErr := mcmp.VtConn.ExecuteFetch("vexplain plan "+query, 1, true)
require.NoError(mcmp.t, vtErr, "[Vitess Error] for query: "+query)
fmt.Printf("Vitess VExplain Plan: \n%v\n", vtQr.Rows[0][0].ToString())
}
3 changes: 3 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func TestSetAndGetLastInsertID(t *testing.T) {
mcmp.Run(name, func(mcmp *utils.MySQLCompare) {
mcmp.Exec(query)
mcmp.Exec("select last_insert_id()")
if mcmp.AsT().Failed() {
mcmp.VExplain(query)
}
})
}
// we need this value to be not zero, and then we keep changing it so different queries don't interact with each other
Expand Down
12 changes: 6 additions & 6 deletions go/vt/vttablet/tabletserver/query_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,9 @@ func (qre *QueryExecutor) execStreamSQL(conn *connpool.PooledConn, isTransaction
callBackClosingSpan := func(result *sqltypes.Result) error {
defer span.Finish()

if err := qre.fetchLastInsertID(ctx, conn.Conn, result); err != nil {
return err
}
// if err := qre.fetchLastInsertID(ctx, conn.Conn, result); err != nil {
// return err
// }

return callback(result)
}
Expand All @@ -1222,9 +1222,9 @@ func (qre *QueryExecutor) execStreamSQL(conn *connpool.PooledConn, isTransaction
// This change will ensure that long-running streaming stateful queries get gracefully shutdown during ServingTypeChange
// once their grace period is over.
qd := NewQueryDetail(qre.logStats.Ctx, conn.Conn)
if err := qre.resetLastInsertIDIfNeeded(ctx, conn.Conn); err != nil {
return err
}
// if err := qre.resetLastInsertIDIfNeeded(ctx, conn.Conn); err != nil {
// return err
// }

if isTransaction {
err := qre.tsv.statefulql.Add(qd)
Expand Down

0 comments on commit 6c1a3d2

Please sign in to comment.