summaryrefslogtreecommitdiff
path: root/src/backend/lib/binaryheap.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-08-30 19:15:21 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2013-08-30 19:15:32 -0400
commit16e8e36cebba8909ec01ca259f32e8dd40090657 (patch)
treea47835e60a8ebc11c675e30cbe40b380f3a27951 /src/backend/lib/binaryheap.c
parentdfed97b744a4706d7c7b410667c0c5bc92d0eb8d (diff)
Reset the binary heap in MergeAppend rescans.
Failing to do so can cause queries to return wrong data, error out or crash. This requires adding a new binaryheap_reset() method to binaryheap.c, but that probably should have been there anyway. Per bug #8410 from Terje Elde. Diagnosis and patch by Andres Freund.
Diffstat (limited to 'src/backend/lib/binaryheap.c')
-rw-r--r--src/backend/lib/binaryheap.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/backend/lib/binaryheap.c b/src/backend/lib/binaryheap.c
index 4b4fc945c32..7125970a50f 100644
--- a/src/backend/lib/binaryheap.c
+++ b/src/backend/lib/binaryheap.c
@@ -36,17 +36,31 @@ binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
binaryheap *heap;
sz = offsetof(binaryheap, bh_nodes) +sizeof(Datum) * capacity;
- heap = palloc(sz);
- heap->bh_size = 0;
+ heap = (binaryheap *) palloc(sz);
heap->bh_space = capacity;
- heap->bh_has_heap_property = true;
heap->bh_compare = compare;
heap->bh_arg = arg;
+ heap->bh_size = 0;
+ heap->bh_has_heap_property = true;
+
return heap;
}
/*
+ * binaryheap_reset
+ *
+ * Resets the heap to an empty state, losing its data content but not the
+ * parameters passed at allocation.
+ */
+void
+binaryheap_reset(binaryheap *heap)
+{
+ heap->bh_size = 0;
+ heap->bh_has_heap_property = true;
+}
+
+/*
* binaryheap_free
*
* Releases memory used by the given binaryheap.