Hi John,

Thanks for the fix. It looks good to me.

> since the blocks can't be freed until the sort ends

The fix also allows whole blocks to be freed during the sort. Large
tuples get their own blocks, and AllocSetFree() calls free(block)
in the MemoryChunkIsExternal() branch (aset.c:1183 on master).

I used mem01 and the settings from your script to check this with
12 kB values.

    BEGIN;
    DECLARE c NO SCROLL CURSOR FOR
      SELECT k, repeat(pad, 12) AS p FROM mem01
      ORDER BY k DESC, p LIMIT 500;
    FETCH 1 FROM c \g /dev/null
    SELECT total_nblocks, total_bytes
      FROM pg_backend_memory_contexts WHERE name = 'Caller tuples';
    COMMIT;

While the cursor was open, I got these results on master.

                    total_nblocks  total_bytes
    without patch            1002     12108280
    with patch                501      6052192

I got the same block counts and total_bytes on REL_15_STABLE.
make check passed on both versions with and without the patch.

Regards,
Rui



Reply via email to