Commit c76665ed authored by Alexander Korotkov's avatar Alexander Korotkov

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
parent ae27b1ac
......@@ -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 */
......
......@@ -643,6 +643,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;
......
......@@ -255,6 +255,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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment