Fix: Make FindShardIntervalIndex robust against 0 shards.

pull/1331/head
Andres Freund 2017-04-27 16:03:05 -07:00
parent 59ecf9faa0
commit ba93d32c8a
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 * the searched value. Note that the searched value must be the hashed value
* of the original value if the distribution method is hash. * of the original value if the distribution method is hash.
* *
* Note that, if the searched value can not be found for hash partitioned tables, * Note that, if the searched value can not be found for hash partitioned
* we error out. This should only happen if something is terribly wrong, either * tables, we error out (unless there are no shards, in which case
* metadata tables are corrupted or we have a bug somewhere. Such as a hash * INVALID_SHARD_INDEX is returned). This should only happen if something is
* function which returns a value not in the range of [INT32_MIN, INT32_MAX] can * terribly wrong, either metadata tables are corrupted or we have a bug
* fire this. * somewhere. Such as a hash function which returns a value not in the range
* of [INT32_MIN, INT32_MAX] can fire this.
*/ */
static int static int
FindShardIntervalIndex(Datum searchedValue, DistTableCacheEntry *cacheEntry) FindShardIntervalIndex(Datum searchedValue, DistTableCacheEntry *cacheEntry)
@ -264,6 +265,11 @@ FindShardIntervalIndex(Datum searchedValue, DistTableCacheEntry *cacheEntry)
!cacheEntry->hasUniformHashDistribution); !cacheEntry->hasUniformHashDistribution);
int shardIndex = INVALID_SHARD_INDEX; int shardIndex = INVALID_SHARD_INDEX;
if (shardCount == 0)
{
return INVALID_SHARD_INDEX;
}
if (partitionMethod == DISTRIBUTE_BY_HASH) if (partitionMethod == DISTRIBUTE_BY_HASH)
{ {
if (useBinarySearch) if (useBinarySearch)