On Fri, Jun 26, 2020 at 3:16 PM Bharath Rupireddy <
bharath.rupireddyforpostg...@gmail.com> wrote:

> Hi Hackers,
>
> There seems to be an extra palloc of 64KB of raw_buf for binary format
> files which is not required
> as copy logic for binary files don't use raw_buf, instead, attribute_buf
> is used in CopyReadBinaryAttribute.
>

+1

I looked at the patch and the changes looked good. Couple of comments;

1)

+
+ /* For binary files raw_buf is not used,
+ * instead, attribute_buf is used in
+ * CopyReadBinaryAttribute. Hence, don't palloc
+ * raw_buf.
+ */

Not a PG style of commenting.

2)  In non-binary mode, should assign NULL the raw_buf.

Attaching patch with those changes.



> Attached is a patch, which places a check to avoid this unnecessary 64KB
> palloc.
>
> Request the community to take this patch, if it is useful.
>
> With Regards,
> Bharath Rupireddy.
> EnterpriseDB: http://www.enterprisedb.com
>


Thanks,
Rushabh Lathia
www.EnterpriseDB.com
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 6d53dc4..97170d3 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -3368,7 +3368,17 @@ BeginCopyFrom(ParseState *pstate,
 	initStringInfo(&cstate->attribute_buf);
 	initStringInfo(&cstate->line_buf);
 	cstate->line_buf_converted = false;
-	cstate->raw_buf = (char *) palloc(RAW_BUF_SIZE + 1);
+
+	/*
+	 * For binary files raw_buf is not used and instead attribute_buf
+	 * is used in CopyReadBinaryAttribute. Hence, don't palloc raw_buf
+	 * for binary files.
+	 */
+	if (!cstate->binary)
+		cstate->raw_buf = (char *) palloc(RAW_BUF_SIZE + 1);
+	else
+		cstate->raw_buf = NULL;
+
 	cstate->raw_buf_index = cstate->raw_buf_len = 0;
 
 	/* Assign range table, we'll need it in CopyFrom. */

Reply via email to