Skip to content

Commit c19615f

Browse files
committed
Disallow setting MAX_PARTITION_BUFFERS to less than 2
Add some comments to mention that this value must be at least 2 and also add a StaticAssertDecl to cause compilation failure if anyone tries to build with an invalid value. The multiInsertBuffers list must have at least two elements due to how the code in CopyMultiInsertInfoFlush() pushes the current ResultRelInfo's CopyMultiInsertBuffer to the end of the list. If the first element is also the last element, bad things will happen. Author: Zhang Mingli <avamingli@gmail.com> Discussion: https://postgr.es/m/CAApHDvpQ6t9ROcqbD-OgqR04Kfq4vQKw79Vo6r5j%2BciHwsSfkA%40mail.gmail.com
1 parent 72fe6d2 commit c19615f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/backend/commands/copyfrom.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@
6868
*/
6969
#define MAX_BUFFERED_BYTES 65535
7070

71-
/* Trim the list of buffers back down to this number after flushing */
71+
/*
72+
* Trim the list of buffers back down to this number after flushing. This
73+
* must be >= 2.
74+
*/
7275
#define MAX_PARTITION_BUFFERS 32
7376

7477
/* Stores multi-insert data related to a single relation in CopyFrom. */
@@ -550,6 +553,13 @@ CopyMultiInsertInfoFlush(CopyMultiInsertInfo *miinfo, ResultRelInfo *curr_rri,
550553
*/
551554
if (buffer->resultRelInfo == curr_rri)
552555
{
556+
/*
557+
* The code below would misbehave if we were trying to reduce the
558+
* list to less than two items.
559+
*/
560+
StaticAssertDecl(MAX_PARTITION_BUFFERS >= 2,
561+
"MAX_PARTITION_BUFFERS must be >= 2");
562+
553563
miinfo->multiInsertBuffers = list_delete_first(miinfo->multiInsertBuffers);
554564
miinfo->multiInsertBuffers = lappend(miinfo->multiInsertBuffers, buffer);
555565
buffer = (CopyMultiInsertBuffer *) linitial(miinfo->multiInsertBuffers);

0 commit comments

Comments
 (0)