Hi all,

partition_bounds_equal() accesses the last datum from the given
partition bounds directly to compare their greatest moduli. Rest of
the code uses get_greatest_modulus() to get the greatest modulus from
a partition bound. partition_bounds_equal() should also do the same
for the sake of consistency and to make sure the in future the code
remains sane if we change the way we store greatest modulus in
PartitionBoundInfoData in future.

-- 
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company
From 6aba3444b75f3420af52f602d7a2f53da8da0847 Mon Sep 17 00:00:00 2001
From: Ashutosh Bapat <ashutosh.ba...@enterprisedb.com>
Date: Fri, 1 Dec 2017 15:36:56 +0530
Subject: [PATCH] Use get_greatest_modulus() in partition_bounds_equal()

partition_bounds_equal() accesses the last datum from the given
partition bounds directly to compare their greatest moduli. Rest of
the code uses get_greatest_modulus() to get the greatest modulus from
a partition bound. Above comparison should also do the same for the
sake of consistency and to make sure the in future the code remains
sane if we change the way we store greatest modulus in
PartitionBoundInfoData.

Ashutosh Bapat.
---
 src/backend/catalog/partition.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c
index 2bf8117..dd4a8d3 100644
--- a/src/backend/catalog/partition.c
+++ b/src/backend/catalog/partition.c
@@ -751,15 +751,13 @@ partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval,
 
 	if (b1->strategy == PARTITION_STRATEGY_HASH)
 	{
-		int			greatest_modulus;
+		int			greatest_modulus = get_greatest_modulus(b1);
 
 		/*
 		 * If two hash partitioned tables have different greatest moduli,
-		 * their partition schemes don't match.  For hash partitioned table,
-		 * the greatest modulus is given by the last datum and number of
-		 * partitions is given by ndatums.
+		 * their partition schemes don't match.
 		 */
-		if (b1->datums[b1->ndatums - 1][0] != b2->datums[b2->ndatums - 1][0])
+		if (greatest_modulus != get_greatest_modulus(b2))
 			return false;
 
 		/*
@@ -773,7 +771,6 @@ partition_bounds_equal(int partnatts, int16 *parttyplen, bool *parttypbyval,
 		 * their indexes array will be same.  So, it suffices to compare
 		 * indexes array.
 		 */
-		greatest_modulus = get_greatest_modulus(b1);
 		for (i = 0; i < greatest_modulus; i++)
 			if (b1->indexes[i] != b2->indexes[i])
 				return false;
-- 
1.7.9.5

Reply via email to