Skip to content

Commit d406ace

Browse files
committed
Only release buffer when a cursor is not in use and still spooling results
1 parent ea55201 commit d406ace

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/handler.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,14 @@ func (h *Handler) resultForDefaultIter(ctx *sql.Context, c *mysql.Conn, schema s
673673
timer := time.NewTimer(waitTime)
674674
defer timer.Stop()
675675

676-
// Wrap the callback to include a BytesBuffer.Reset() to clean out rows that have already been spooled
676+
// Wrap the callback to include a BytesBuffer.Reset() for non-cursor requests, to
677+
// clean out rows that have already been spooled.
677678
resetCallback := func(r *sqltypes.Result, more bool) error {
678-
defer buf.Reset()
679+
// A server-side cursor allows the caller to fetch results cached on the server-side,
680+
// so if a cursor exists, we can't release the buffer memory yet.
681+
if c.StatusFlags&uint16(mysql.ServerCursorExists) != 0 {
682+
defer buf.Reset()
683+
}
679684
return callback(r, more)
680685
}
681686

0 commit comments

Comments
 (0)