Re: A potential memory leak on Merge Join when Sort node is not below Materialize node

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Önder Kalacı <onderkalaci(at)gmail(dot)com>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: A potential memory leak on Merge Join when Sort node is not below Materialize node
Date: 2022-09-28 17:35:55
Message-ID: 4016980.1664386555@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

=?UTF-8?B?w5ZuZGVyIEthbGFjxLE=?= <onderkalaci(at)gmail(dot)com> writes:
> With PG 15 (rc1 or beta4), I'm observing an interesting memory pattern.

Yup, that is a leak. valgrind'ing it blames this call chain:

==00:00:16:12.228 4011013== 790,404,056 bytes in 60,800,312 blocks are definitely lost in loss record 1,108 of 1,108
==00:00:16:12.228 4011013== at 0x9A5104: palloc (mcxt.c:1170)
==00:00:16:12.228 4011013== by 0x89F8D9: datumCopy (datum.c:175)
==00:00:16:12.228 4011013== by 0x9B5BEE: tuplesort_getdatum (tuplesortvariants.c:882)
==00:00:16:12.228 4011013== by 0x6FA8B3: ExecSort (nodeSort.c:200)
==00:00:16:12.228 4011013== by 0x6F1E87: ExecProcNode (executor.h:259)
==00:00:16:12.228 4011013== by 0x6F1E87: ExecMergeJoin (nodeMergejoin.c:871)
==00:00:16:12.228 4011013== by 0x6D7800: ExecProcNode (executor.h:259)
==00:00:16:12.228 4011013== by 0x6D7800: fetch_input_tuple (nodeAgg.c:562)
==00:00:16:12.228 4011013== by 0x6DAE2E: agg_retrieve_direct (nodeAgg.c:2454)
==00:00:16:12.228 4011013== by 0x6DAE2E: ExecAgg (nodeAgg.c:2174)
==00:00:16:12.228 4011013== by 0x6C6122: ExecProcNode (executor.h:259)
==00:00:16:12.228 4011013== by 0x6C6122: ExecutePlan (execMain.c:1636)

and bisecting fingers this commit as the guilty party:

commit 91e9e89dccdfdf4216953d3d8f5515dcdef177fb
Author: David Rowley <drowley(at)postgresql(dot)org>
Date: Thu Jul 22 14:03:19 2021 +1200

Make nodeSort.c use Datum sorts for single column sorts

Looks like that forgot that tuplesort_getdatum()'s result has to
be freed by the caller.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2022-09-28 17:40:28 Re: Adding CommandID to heap xlog records
Previous Message Ranier Vilela 2022-09-28 17:29:57 Re: A potential memory leak on Merge Join when Sort node is not below Materialize node