@@ -127,6 +127,8 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
127
127
List * restrictInfoList = NIL ;
128
128
Node * baseConstraint = NULL ;
129
129
int shardHashCode = -1 ;
130
+ int shardCount = shardIntervalList -> length ;
131
+ uint32 hashTokenIncrement = (uint32 )(HASH_TOKEN_COUNT / shardCount );
130
132
Var * partitionColumn = PartitionColumn (relationId );
131
133
char partitionMethod = PartitionType (relationId );
132
134
@@ -168,8 +170,6 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
168
170
if (OidIsValid (hashFunction -> fn_oid ))
169
171
{
170
172
int hashedValue = DatumGetInt32 (FunctionCall1 (hashFunction , constant -> constvalue ));
171
- int shardCount = shardIntervalList -> length ;
172
- uint32 hashTokenIncrement = (uint32 )(HASH_TOKEN_COUNT / shardCount );
173
173
shardHashCode = (int )((uint32 )(hashedValue - INT32_MIN ) / hashTokenIncrement );
174
174
remainingShardList = LookupShardPlacementCache (relationId , shardHashCode );
175
175
if (remainingShardList != NULL )
@@ -229,7 +229,19 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
229
229
}
230
230
if (shardHashCode >= 0 )
231
231
{
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
+ }
233
245
}
234
246
return remainingShardList ;
235
247
}
0 commit comments