Minor improvement to partition_bounds_copy()

Started by Etsuro Fujitaalmost 6 years ago4 messages
#1Etsuro Fujita
etsuro.fujita@gmail.com
1 attachment(s)

partition_bounds_copy() sets the hash_part and natts variable in each
iteration of a loop to copy the datums in the datums array, which
would not be efficient. Attached is small patch for avoiding that.

Best regards,
Etsuro Fujita

Attachments:

partition_bounds_copy.patchapplication/octet-stream; name=partition_bounds_copy.patchDownload
diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c
index 2d61c3f6e3..54eb83a0d1 100644
--- a/src/backend/partitioning/partbounds.c
+++ b/src/backend/partitioning/partbounds.c
@@ -789,6 +789,8 @@ partition_bounds_copy(PartitionBoundInfo src,
 	int			ndatums;
 	int			partnatts;
 	int			num_indexes;
+	bool		hash_part;
+	int			natts;
 
 	dest = (PartitionBoundInfo) palloc(sizeof(PartitionBoundInfoData));
 
@@ -819,17 +821,17 @@ partition_bounds_copy(PartitionBoundInfo src,
 	else
 		dest->kind = NULL;
 
+	/*
+	 * For hash partitioning, datums array will have two elements - modulus and
+	 * remainder.
+	 */
+	hash_part = (key->strategy == PARTITION_STRATEGY_HASH);
+	natts = hash_part ? 2 : partnatts;
+
 	for (i = 0; i < ndatums; i++)
 	{
 		int			j;
 
-		/*
-		 * For a corresponding hash partition, datums array will have two
-		 * elements - modulus and remainder.
-		 */
-		bool		hash_part = (key->strategy == PARTITION_STRATEGY_HASH);
-		int			natts = hash_part ? 2 : partnatts;
-
 		dest->datums[i] = (Datum *) palloc(sizeof(Datum) * natts);
 
 		for (j = 0; j < natts; j++)
#2Amit Langote
amitlangote09@gmail.com
In reply to: Etsuro Fujita (#1)
Re: Minor improvement to partition_bounds_copy()

Fujita-san,

On Thu, Feb 20, 2020 at 8:36 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

partition_bounds_copy() sets the hash_part and natts variable in each
iteration of a loop to copy the datums in the datums array, which
would not be efficient. Attached is small patch for avoiding that.

That looks good to me.

Thanks,
Amit

#3Julien Rouhaud
rjuju123@gmail.com
In reply to: Amit Langote (#2)
Re: Minor improvement to partition_bounds_copy()

On Thu, Feb 20, 2020 at 09:38:26PM +0900, Amit Langote wrote:

Fujita-san,

On Thu, Feb 20, 2020 at 8:36 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

partition_bounds_copy() sets the hash_part and natts variable in each
iteration of a loop to copy the datums in the datums array, which
would not be efficient. Attached is small patch for avoiding that.

That looks good to me.

Looks good to me too!

#4Etsuro Fujita
etsuro.fujita@gmail.com
In reply to: Julien Rouhaud (#3)
Re: Minor improvement to partition_bounds_copy()

On Thu, Feb 20, 2020 at 10:52 PM Julien Rouhaud <rjuju123@gmail.com> wrote:

On Thu, Feb 20, 2020 at 09:38:26PM +0900, Amit Langote wrote:

On Thu, Feb 20, 2020 at 8:36 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

partition_bounds_copy() sets the hash_part and natts variable in each
iteration of a loop to copy the datums in the datums array, which
would not be efficient. Attached is small patch for avoiding that.

That looks good to me.

Looks good to me too!

Pushed. Thanks, Amit and Julien!

Best regards,
Etsuro Fujita