Fix: Make FindShardIntervalIndex robust against 0 shards.

release-6.1
Andres Freund 2017-04-27 16:03:05 -07:00 committed by Jason Petersen
parent 6dbd434f81
commit 5b6dd0812d
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
1 changed files with 11 additions and 5 deletions

View File

@ -247,11 +247,12 @@ FindShardInterval(Datum partitionColumnValue, DistTableCacheEntry *cacheEntry)
* the searched value. Note that the searched value must be the hashed value
* of the original value if the distribution method is hash.
*
* Note that, if the searched value can not be found for hash partitioned tables,
* we error out. This should only happen if something is terribly wrong, either
* metadata tables are corrupted or we have a bug somewhere. Such as a hash
* function which returns a value not in the range of [INT32_MIN, INT32_MAX] can
* fire this.
* Note that, if the searched value can not be found for hash partitioned
* tables, we error out (unless there are no shards, in which case
* INVALID_SHARD_INDEX is returned). This should only happen if something is
* terribly wrong, either metadata tables are corrupted or we have a bug
* somewhere. Such as a hash function which returns a value not in the range
* of [INT32_MIN, INT32_MAX] can fire this.
*/
static int
FindShardIntervalIndex(Datum searchedValue, DistTableCacheEntry *cacheEntry)
@ -264,6 +265,11 @@ FindShardIntervalIndex(Datum searchedValue, DistTableCacheEntry *cacheEntry)
!cacheEntry->hasUniformHashDistribution);
int shardIndex = INVALID_SHARD_INDEX;
if (shardCount == 0)
{
return INVALID_SHARD_INDEX;
}
if (partitionMethod == DISTRIBUTE_BY_HASH)
{
if (useBinarySearch)