Fix memory leak in IndexScan node with reordering

Fix ExecReScanIndexScan() to free the referenced tuples while emptying the
priority queue.  Backpatch to all supported versions.

Discussion: https://postgr.es/m/CAHqSB9gECMENBQmpbv5rvmT3HTaORmMK3Ukg73DsX5H7EJV7jw%40mail.gmail.com
Author: Aliaksandr Kalenik
Reviewed-by: Tom Lane, Alexander Korotkov
Backpatch-through: 10
This commit is contained in:
Alexander Korotkov 2022-02-14 03:26:55 +03:00
parent c963e84fb8
commit 3f74daa8df
3 changed files with 36 additions and 1 deletions

View File

@ -574,8 +574,12 @@ ExecReScanIndexScan(IndexScanState *node)
/* flush the reorder queue */
if (node->iss_ReorderQueue)
{
HeapTuple tuple;
while (!pairingheap_is_empty(node->iss_ReorderQueue))
reorderqueue_pop(node);
{
tuple = reorderqueue_pop(node);
heap_freetuple(tuple);
}
}
/* reset index scan */

View File

@ -588,6 +588,33 @@ SELECT circle_center(f1), round(radius(f1)) as radius FROM gcircle_tbl ORDER BY
(751.5,2655) | 20
(10 rows)
EXPLAIN (COSTS OFF)
SELECT point(x,x), (SELECT f1 FROM gpolygon_tbl ORDER BY f1 <-> point(x,x) LIMIT 1) as c FROM generate_series(0,10,1) x;
QUERY PLAN
--------------------------------------------------------------------------------------------
Function Scan on generate_series x
SubPlan 1
-> Limit
-> Index Scan using ggpolygonind on gpolygon_tbl
Order By: (f1 <-> point((x.x)::double precision, (x.x)::double precision))
(5 rows)
SELECT point(x,x), (SELECT f1 FROM gpolygon_tbl ORDER BY f1 <-> point(x,x) LIMIT 1) as c FROM generate_series(0,10,1) x;
point | c
---------+-------------------------------------------
(0,0) | ((240,359),(240,455),(337,455),(337,359))
(1,1) | ((240,359),(240,455),(337,455),(337,359))
(2,2) | ((240,359),(240,455),(337,455),(337,359))
(3,3) | ((240,359),(240,455),(337,455),(337,359))
(4,4) | ((240,359),(240,455),(337,455),(337,359))
(5,5) | ((240,359),(240,455),(337,455),(337,359))
(6,6) | ((240,359),(240,455),(337,455),(337,359))
(7,7) | ((240,359),(240,455),(337,455),(337,359))
(8,8) | ((240,359),(240,455),(337,455),(337,359))
(9,9) | ((240,359),(240,455),(337,455),(337,359))
(10,10) | ((240,359),(240,455),(337,455),(337,359))
(11 rows)
-- Now check the results from bitmap indexscan
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;

View File

@ -239,6 +239,10 @@ EXPLAIN (COSTS OFF)
SELECT circle_center(f1), round(radius(f1)) as radius FROM gcircle_tbl ORDER BY f1 <-> '(200,300)'::point LIMIT 10;
SELECT circle_center(f1), round(radius(f1)) as radius FROM gcircle_tbl ORDER BY f1 <-> '(200,300)'::point LIMIT 10;
EXPLAIN (COSTS OFF)
SELECT point(x,x), (SELECT f1 FROM gpolygon_tbl ORDER BY f1 <-> point(x,x) LIMIT 1) as c FROM generate_series(0,10,1) x;
SELECT point(x,x), (SELECT f1 FROM gpolygon_tbl ORDER BY f1 <-> point(x,x) LIMIT 1) as c FROM generate_series(0,10,1) x;
-- Now check the results from bitmap indexscan
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;