summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley2024-07-30 08:19:59 +0000
committerDavid Rowley2024-07-30 08:19:59 +0000
commitc19615fe391c9577e2129fed4429736f6b5295da (patch)
tree90cfa13cb2056cba322a3ba86f2ededef8fa54e6
parent72fe6d24a38c88e112d5e63a8e907c3e96ae46ad (diff)
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 <[email protected]> Discussion: https://postgr.es/m/CAApHDvpQ6t9ROcqbD-OgqR04Kfq4vQKw79Vo6r5j%2BciHwsSfkA%40mail.gmail.com
-rw-r--r--src/backend/commands/copyfrom.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c
index ce4d62e707..c42a5621d5 100644
--- a/src/backend/commands/copyfrom.c
+++ b/src/backend/commands/copyfrom.c
@@ -68,7 +68,10 @@
*/
#define MAX_BUFFERED_BYTES 65535
-/* Trim the list of buffers back down to this number after flushing */
+/*
+ * Trim the list of buffers back down to this number after flushing. This
+ * must be >= 2.
+ */
#define MAX_PARTITION_BUFFERS 32
/* Stores multi-insert data related to a single relation in CopyFrom. */
@@ -550,6 +553,13 @@ CopyMultiInsertInfoFlush(CopyMultiInsertInfo *miinfo, ResultRelInfo *curr_rri,
*/
if (buffer->resultRelInfo == curr_rri)
{
+ /*
+ * The code below would misbehave if we were trying to reduce the
+ * list to less than two items.
+ */
+ StaticAssertDecl(MAX_PARTITION_BUFFERS >= 2,
+ "MAX_PARTITION_BUFFERS must be >= 2");
+
miinfo->multiInsertBuffers = list_delete_first(miinfo->multiInsertBuffers);
miinfo->multiInsertBuffers = lappend(miinfo->multiInsertBuffers, buffer);
buffer = (CopyMultiInsertBuffer *) linitial(miinfo->multiInsertBuffers);