Avoid calling hash functions with InvalidOid collation

I opted to try find the correct collation as opposed to DEFAULT_COLLATION_OID
read_write_etc
Philip Dubé 2019-07-16 18:43:19 +00:00
parent b9bb4388d3
commit 90179cf615
4 changed files with 8 additions and 3 deletions

View File

@ -84,7 +84,7 @@ worker_hash(PG_FUNCTION_ARGS)
fmgr_info_copy(hashFunction, &(typeEntry->hash_proc_finfo), CurrentMemoryContext); fmgr_info_copy(hashFunction, &(typeEntry->hash_proc_finfo), CurrentMemoryContext);
/* calculate hash value */ /* calculate hash value */
hashedValueDatum = FunctionCall1(hashFunction, valueDatum); hashedValueDatum = FunctionCall1Coll(hashFunction, PG_GET_COLLATION(), valueDatum);
PG_RETURN_INT32(hashedValueDatum); PG_RETURN_INT32(hashedValueDatum);
} }

View File

@ -253,7 +253,9 @@ FindShardInterval(Datum partitionColumnValue, DistTableCacheEntry *cacheEntry)
if (cacheEntry->partitionMethod == DISTRIBUTE_BY_HASH) if (cacheEntry->partitionMethod == DISTRIBUTE_BY_HASH)
{ {
searchedValue = FunctionCall1(cacheEntry->hashFunction, partitionColumnValue); searchedValue = FunctionCall1Coll(cacheEntry->hashFunction,
cacheEntry->partitionColumn->varcollid,
partitionColumnValue);
} }
shardIndex = FindShardIntervalIndex(searchedValue, cacheEntry); shardIndex = FindShardIntervalIndex(searchedValue, cacheEntry);

View File

@ -221,6 +221,7 @@ worker_hash_partition_table(PG_FUNCTION_ARGS)
partitionContext->hashFunction = hashFunction; partitionContext->hashFunction = hashFunction;
partitionContext->partitionCount = partitionCount; partitionContext->partitionCount = partitionCount;
partitionContext->collation = PG_GET_COLLATION();
/* we'll use binary search, we need the comparison function */ /* we'll use binary search, we need the comparison function */
if (!partitionContext->hasUniformHashDistribution) if (!partitionContext->hasUniformHashDistribution)
@ -1256,7 +1257,8 @@ HashPartitionId(Datum partitionValue, const void *context)
ShardInterval **syntheticShardIntervalArray = ShardInterval **syntheticShardIntervalArray =
hashPartitionContext->syntheticShardIntervalArray; hashPartitionContext->syntheticShardIntervalArray;
FmgrInfo *comparisonFunction = hashPartitionContext->comparisonFunction; FmgrInfo *comparisonFunction = hashPartitionContext->comparisonFunction;
Datum hashDatum = FunctionCall1(hashFunction, partitionValue); Datum hashDatum = FunctionCall1Coll(hashFunction, hashPartitionContext->collation,
partitionValue);
int32 hashResult = 0; int32 hashResult = 0;
uint32 hashPartitionId = 0; uint32 hashPartitionId = 0;

View File

@ -79,6 +79,7 @@ typedef struct HashPartitionContext
FmgrInfo *comparisonFunction; FmgrInfo *comparisonFunction;
ShardInterval **syntheticShardIntervalArray; ShardInterval **syntheticShardIntervalArray;
uint32 partitionCount; uint32 partitionCount;
Oid collation;
bool hasUniformHashDistribution; bool hasUniformHashDistribution;
} HashPartitionContext; } HashPartitionContext;