@@ -127,6 +127,8 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
127127 List * restrictInfoList = NIL ;
128128 Node * baseConstraint = NULL ;
129129 int shardHashCode = -1 ;
130+ int shardCount = shardIntervalList -> length ;
131+ uint32 hashTokenIncrement = (uint32 )(HASH_TOKEN_COUNT / shardCount );
130132 Var * partitionColumn = PartitionColumn (relationId );
131133 char partitionMethod = PartitionType (relationId );
132134
@@ -168,8 +170,6 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
168170 if (OidIsValid (hashFunction -> fn_oid ))
169171 {
170172 int hashedValue = DatumGetInt32 (FunctionCall1 (hashFunction , constant -> constvalue ));
171- int shardCount = shardIntervalList -> length ;
172- uint32 hashTokenIncrement = (uint32 )(HASH_TOKEN_COUNT / shardCount );
173173 shardHashCode = (int )((uint32 )(hashedValue - INT32_MIN ) / hashTokenIncrement );
174174 remainingShardList = LookupShardPlacementCache (relationId , shardHashCode );
175175 if (remainingShardList != NULL )
@@ -229,7 +229,19 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
229229 }
230230 if (shardHashCode >= 0 )
231231 {
232- AddToShardPlacementCache (relationId , shardHashCode , shardIntervalList -> length , remainingShardList );
232+ ShardInterval * shardInterval = (ShardInterval * ) linitial (remainingShardList );
233+ int64 shardId = shardInterval -> id ;
234+ int32 shardMinHashToken = INT32_MIN + (shardId * hashTokenIncrement );
235+ int32 shardMaxHashToken = shardMinHashToken + (hashTokenIncrement - 1 );
236+ if (shardId == (shardCount - 1 ))
237+ {
238+ shardMaxHashToken = INT32_MAX ;
239+ }
240+ if (DatumGetInt32 (shardInterval -> minValue ) == shardMinHashToken &&
241+ DatumGetInt32 (shardInterval -> maxValue ) == shardMaxHashToken )
242+ {
243+ AddToShardPlacementCache (relationId , shardHashCode , shardIntervalList -> length , remainingShardList );
244+ }
233245 }
234246 return remainingShardList ;
235247}
0 commit comments