Skip to content

Commit 50ed238

Browse files
author
James Cor
committed
reset memory
1 parent 431ae01 commit 50ed238

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

server/handler.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,17 @@ func (h *Handler) resultForValueRowIter(ctx *sql.Context, c *mysql.Conn, schema
807807
wg := sync.WaitGroup{}
808808
wg.Add(2)
809809

810+
// Wrap the callback to include a BytesBuffer.Reset() for non-cursor requests, to
811+
// clean out rows that have already been spooled.
812+
resetCallback := func(r *sqltypes.Result, more bool) error {
813+
// A server-side cursor allows the caller to fetch results cached on the server-side,
814+
// so if a cursor exists, we can't release the buffer memory yet.
815+
if c.StatusFlags&uint16(mysql.ServerCursorExists) != 0 {
816+
defer buf.Reset()
817+
}
818+
return callback(r, more)
819+
}
820+
810821
// TODO: send results instead of rows?
811822
// Read rows from iter and send them off
812823
var rowChan = make(chan sql.ValueRow, 512)
@@ -849,7 +860,7 @@ func (h *Handler) resultForValueRowIter(ctx *sql.Context, c *mysql.Conn, schema
849860
}
850861
}
851862
if res.RowsAffected == rowsBatch {
852-
if err := callback(res, more); err != nil {
863+
if err := resetCallback(res, more); err != nil {
853864
return err
854865
}
855866
res = nil

0 commit comments

Comments
 (0)