Re: [PATCH] nodeindexscan with reorder memory leak

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aliaksandr Kalenik <akalenik(at)kontur(dot)io>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Re: [PATCH] nodeindexscan with reorder memory leak
Date: 2022-01-30 16:24:35
Message-ID: 233587.1643559875@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Aliaksandr Kalenik <akalenik(at)kontur(dot)io> writes:
> I was investigating a leak reported in the PostGIS issues tracker [1] which
> led me to the Postgres side where the problem really is. The leak is
> reproducible with query from original ticket [1]:
> ...
> The leak is only noticeable when index scan with reorder happens as part of
> subquery plan which is explained by the fact that heap tuples cloned in
> reorderqueue_push are not freed during flush of reorder queue in
> ExecReScanIndex.

Actually, that code has got worse problems than that. I tried to improve
our regression tests to exercise that code path, as attached. What I got
was

+SELECT point(x,x), (SELECT circle_center(f1) FROM gcircle_tbl ORDER BY f1 <-> p
oint(x,x) LIMIT 1) as c FROM generate_series(0,1000,1) x;
+ERROR: index returned tuples in wrong order

(The error doesn't always appear depending on what generate_series
parameters you use, but it seems to show up consistently with
a step of 1 and a limit of 1000 or more.)

Fixing this is well beyond my knowledge of that code, so I'm punting
it to the original authors.

regards, tom lane

Attachment Content-Type Size
failing-test-case.patch text/x-diff 895 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2022-01-30 17:00:50 Re: Why is INSERT-driven autovacuuming based on pg_class.reltuples?
Previous Message Tom Lane 2022-01-30 16:02:55 Re: [PATCH] nodeindexscan with reorder memory leak