diff --git a/server/conn.go b/server/conn.go index 113efd1d0a8e1..0209ab77171a5 100644 --- a/server/conn.go +++ b/server/conn.go @@ -2190,10 +2190,15 @@ func (cc *clientConn) writeChunks(ctx context.Context, rs ResultSet, binary bool // fetchSize, the desired number of rows to be fetched each time when client uses cursor. func (cc *clientConn) writeChunksWithFetchSize(ctx context.Context, rs ResultSet, serverStatus uint16, fetchSize int) error { fetchedRows := rs.GetFetchedRows() + // if fetchedRows is not enough, getting data from recordSet. + req := rs.NewChunk(nil) for len(fetchedRows) < fetchSize { - // if fetchedRows is not enough, getting data from recordSet. - req := rs.NewChunk(cc.chunkAlloc) + // NOTE: chunk should not be allocated from the allocator + // the allocator will reset every statement + // but it maybe stored in the result set among statements + // ref https://github.com/pingcap/tidb/blob/7fc6ebbda4ddf84c0ba801ca7ebb636b934168cf/server/conn_stmt.go#L233-L239 // Here server.tidbResultSet implements Next method. + req.Reset() if err := rs.Next(ctx, req); err != nil { return err } @@ -2205,7 +2210,6 @@ func (cc *clientConn) writeChunksWithFetchSize(ctx context.Context, rs ResultSet for i := 0; i < rowCount; i++ { fetchedRows = append(fetchedRows, req.GetRow(i)) } - req = chunk.Renew(req, cc.ctx.GetSessionVars().MaxChunkSize) } // tell the client COM_STMT_FETCH has finished by setting proper serverStatus,