From 5d6c8dd8ea75179e382c5b4c9a3ebd5aceb4ea67 Mon Sep 17 00:00:00 2001 From: Zhang Mingli Date: Tue, 30 Jul 2024 14:59:13 +0800 Subject: [PATCH] Add comments for MAX_PARTITION_BUFFERS to avoid misbehave. MAX_PARTITION_BUFFERS should always be > 1 to make sense of copy buffer.If it's set to 0, non-partition tables would clean up buffer and get a null pointer next insertion. Authored-by: Zhang Mingli avamingli@gmail.com --- src/backend/commands/copyfrom.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c index ce4d62e707..b2baf3d29e 100644 --- a/src/backend/commands/copyfrom.c +++ b/src/backend/commands/copyfrom.c @@ -68,7 +68,12 @@ */ #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 should be > 1 to make sense of multi insert buffer. + * Ex: avoid non-partition tables call CopyMultiInsertBufferCleanup() + * when flush buffer. + */ #define MAX_PARTITION_BUFFERS 32 /* Stores multi-insert data related to a single relation in CopyFrom. */ @@ -532,6 +537,8 @@ CopyMultiInsertInfoFlush(CopyMultiInsertInfo *miinfo, ResultRelInfo *curr_rri, miinfo->bufferedTuples = 0; miinfo->bufferedBytes = 0; + Assert(MAX_PARTITION_BUFFERS > 1); + /* * Trim the list of tracked buffers down if it exceeds the limit. Here we * remove buffers starting with the ones we created first. It seems less -- 2.34.1