Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e2b71d

Browse files
committed
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.
1 parent9381cb5 commit8e2b71d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

‎src/backend/executor/nodeMergeAppend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,6 @@ ExecReScanMergeAppend(MergeAppendState *node)
297297
if (subnode->chgParam==NULL)
298298
ExecReScan(subnode);
299299
}
300+
binaryheap_reset(node->ms_heap);
300301
node->ms_initialized= false;
301302
}

‎src/backend/lib/binaryheap.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,30 @@ binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
3636
binaryheap*heap;
3737

3838
sz= offsetof(binaryheap,bh_nodes)+sizeof(Datum)*capacity;
39-
heap=palloc(sz);
40-
heap->bh_size=0;
39+
heap= (binaryheap*)palloc(sz);
4140
heap->bh_space=capacity;
42-
heap->bh_has_heap_property= true;
4341
heap->bh_compare=compare;
4442
heap->bh_arg=arg;
4543

44+
heap->bh_size=0;
45+
heap->bh_has_heap_property= true;
46+
4647
returnheap;
4748
}
4849

50+
/*
51+
* binaryheap_reset
52+
*
53+
* Resets the heap to an empty state, losing its data content but not the
54+
* parameters passed at allocation.
55+
*/
56+
void
57+
binaryheap_reset(binaryheap*heap)
58+
{
59+
heap->bh_size=0;
60+
heap->bh_has_heap_property= true;
61+
}
62+
4963
/*
5064
* binaryheap_free
5165
*

‎src/include/lib/binaryheap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct binaryheap
4040
externbinaryheap*binaryheap_allocate(intcapacity,
4141
binaryheap_comparatorcompare,
4242
void*arg);
43+
externvoidbinaryheap_reset(binaryheap*heap);
4344
externvoidbinaryheap_free(binaryheap*heap);
4445
externvoidbinaryheap_add_unordered(binaryheap*heap,Datumd);
4546
externvoidbinaryheap_build(binaryheap*heap);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp