Fix some ill-chosen names for globally-visible partition support functions.
"compute_hash_value" is particularly gratuitously generic, but IMO all of these ought to have names clearly related to partitioning.
This commit is contained in:
parent
e23bae82cf
commit
19832753f1
@ -855,7 +855,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
|
||||
*/
|
||||
if (OidIsValid(defaultPartOid))
|
||||
{
|
||||
check_default_allows_bound(parent, defaultRel, bound);
|
||||
check_default_partition_contents(parent, defaultRel, bound);
|
||||
/* Keep the lock until commit. */
|
||||
heap_close(defaultRel, NoLock);
|
||||
}
|
||||
|
@ -1085,17 +1085,20 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
int part_index = -1;
|
||||
PartitionKey key = RelationGetPartitionKey(relation);
|
||||
PartitionDesc partdesc = RelationGetPartitionDesc(relation);
|
||||
PartitionBoundInfo boundinfo = partdesc->boundinfo;
|
||||
|
||||
/* Route as appropriate based on partitioning strategy. */
|
||||
switch (key->strategy)
|
||||
{
|
||||
case PARTITION_STRATEGY_HASH:
|
||||
{
|
||||
PartitionBoundInfo boundinfo = partdesc->boundinfo;
|
||||
int greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
||||
uint64 rowHash = compute_hash_value(key->partnatts,
|
||||
key->partsupfunc,
|
||||
values, isnull);
|
||||
int greatest_modulus;
|
||||
uint64 rowHash;
|
||||
|
||||
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
||||
rowHash = compute_partition_hash_value(key->partnatts,
|
||||
key->partsupfunc,
|
||||
values, isnull);
|
||||
|
||||
part_index = boundinfo->indexes[rowHash % greatest_modulus];
|
||||
}
|
||||
@ -1104,8 +1107,8 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
case PARTITION_STRATEGY_LIST:
|
||||
if (isnull[0])
|
||||
{
|
||||
if (partition_bound_accepts_nulls(partdesc->boundinfo))
|
||||
part_index = partdesc->boundinfo->null_index;
|
||||
if (partition_bound_accepts_nulls(boundinfo))
|
||||
part_index = boundinfo->null_index;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1113,10 +1116,10 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
|
||||
bound_offset = partition_list_bsearch(key->partsupfunc,
|
||||
key->partcollation,
|
||||
partdesc->boundinfo,
|
||||
boundinfo,
|
||||
values[0], &equal);
|
||||
if (bound_offset >= 0 && equal)
|
||||
part_index = partdesc->boundinfo->indexes[bound_offset];
|
||||
part_index = boundinfo->indexes[bound_offset];
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1143,7 +1146,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
{
|
||||
bound_offset = partition_range_datum_bsearch(key->partsupfunc,
|
||||
key->partcollation,
|
||||
partdesc->boundinfo,
|
||||
boundinfo,
|
||||
key->partnatts,
|
||||
values,
|
||||
&equal);
|
||||
@ -1154,7 +1157,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
* bound of the partition we're looking for, if there
|
||||
* actually exists one.
|
||||
*/
|
||||
part_index = partdesc->boundinfo->indexes[bound_offset + 1];
|
||||
part_index = boundinfo->indexes[bound_offset + 1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1169,7 +1172,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||
* the default partition, if there is one.
|
||||
*/
|
||||
if (part_index < 0)
|
||||
part_index = partdesc->boundinfo->default_index;
|
||||
part_index = boundinfo->default_index;
|
||||
|
||||
return part_index;
|
||||
}
|
||||
|
@ -470,8 +470,8 @@ check_new_partition_bound(char *relname, Relation parent,
|
||||
*upper;
|
||||
|
||||
Assert(spec->strategy == PARTITION_STRATEGY_RANGE);
|
||||
lower = make_one_range_bound(key, -1, spec->lowerdatums, true);
|
||||
upper = make_one_range_bound(key, -1, spec->upperdatums, false);
|
||||
lower = make_one_partition_rbound(key, -1, spec->lowerdatums, true);
|
||||
upper = make_one_partition_rbound(key, -1, spec->upperdatums, false);
|
||||
|
||||
/*
|
||||
* First check if the resulting range would be empty with
|
||||
@ -589,15 +589,15 @@ check_new_partition_bound(char *relname, Relation parent,
|
||||
}
|
||||
|
||||
/*
|
||||
* check_default_allows_bound
|
||||
* check_default_partition_contents
|
||||
*
|
||||
* This function checks if there exists a row in the default partition that
|
||||
* would properly belong to the new partition being added. If it finds one,
|
||||
* it throws an error.
|
||||
*/
|
||||
void
|
||||
check_default_allows_bound(Relation parent, Relation default_rel,
|
||||
PartitionBoundSpec *new_spec)
|
||||
check_default_partition_contents(Relation parent, Relation default_rel,
|
||||
PartitionBoundSpec *new_spec)
|
||||
{
|
||||
List *new_part_constraints;
|
||||
List *def_part_constraints;
|
||||
@ -757,14 +757,14 @@ get_hash_partition_greatest_modulus(PartitionBoundInfo bound)
|
||||
}
|
||||
|
||||
/*
|
||||
* make_one_range_bound
|
||||
* make_one_partition_rbound
|
||||
*
|
||||
* Return a PartitionRangeBound given a list of PartitionRangeDatum elements
|
||||
* and a flag telling whether the bound is lower or not. Made into a function
|
||||
* because there are multiple sites that want to use this facility.
|
||||
*/
|
||||
PartitionRangeBound *
|
||||
make_one_range_bound(PartitionKey key, int index, List *datums, bool lower)
|
||||
make_one_partition_rbound(PartitionKey key, int index, List *datums, bool lower)
|
||||
{
|
||||
PartitionRangeBound *bound;
|
||||
ListCell *lc;
|
||||
@ -2052,13 +2052,13 @@ get_range_nulltest(PartitionKey key)
|
||||
}
|
||||
|
||||
/*
|
||||
* compute_hash_value
|
||||
* compute_partition_hash_value
|
||||
*
|
||||
* Compute the hash value for given not null partition key values.
|
||||
* Compute the hash value for given partition key values.
|
||||
*/
|
||||
uint64
|
||||
compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||
Datum *values, bool *isnull)
|
||||
compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||
Datum *values, bool *isnull)
|
||||
{
|
||||
int i;
|
||||
uint64 rowHash = 0;
|
||||
@ -2066,6 +2066,7 @@ compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||
|
||||
for (i = 0; i < partnatts; i++)
|
||||
{
|
||||
/* Nulls are just ignored */
|
||||
if (!isnull[i])
|
||||
{
|
||||
Datum hash;
|
||||
|
@ -2018,7 +2018,8 @@ get_matching_hash_bounds(PartitionPruneContext *context,
|
||||
isnull[i] = bms_is_member(i, nullkeys);
|
||||
|
||||
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
||||
rowHash = compute_hash_value(partnatts, partsupfunc, values, isnull);
|
||||
rowHash = compute_partition_hash_value(partnatts, partsupfunc,
|
||||
values, isnull);
|
||||
|
||||
if (partindices[rowHash % greatest_modulus] >= 0)
|
||||
result->bound_offsets =
|
||||
|
8
src/backend/utils/cache/partcache.c
vendored
8
src/backend/utils/cache/partcache.c
vendored
@ -499,10 +499,10 @@ RelationBuildPartitionDesc(Relation rel)
|
||||
continue;
|
||||
}
|
||||
|
||||
lower = make_one_range_bound(key, i, spec->lowerdatums,
|
||||
true);
|
||||
upper = make_one_range_bound(key, i, spec->upperdatums,
|
||||
false);
|
||||
lower = make_one_partition_rbound(key, i, spec->lowerdatums,
|
||||
true);
|
||||
upper = make_one_partition_rbound(key, i, spec->upperdatums,
|
||||
false);
|
||||
all_bounds[ndatums++] = lower;
|
||||
all_bounds[ndatums++] = upper;
|
||||
i++;
|
||||
|
@ -105,8 +105,8 @@ typedef struct PartitionRangeBound
|
||||
} PartitionRangeBound;
|
||||
|
||||
extern int get_hash_partition_greatest_modulus(PartitionBoundInfo b);
|
||||
extern uint64 compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||
Datum *values, bool *isnull);
|
||||
extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||
Datum *values, bool *isnull);
|
||||
extern List *get_qual_from_partbound(Relation rel, Relation parent,
|
||||
PartitionBoundSpec *spec);
|
||||
extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
|
||||
@ -116,11 +116,12 @@ extern PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src,
|
||||
PartitionKey key);
|
||||
extern void check_new_partition_bound(char *relname, Relation parent,
|
||||
PartitionBoundSpec *spec);
|
||||
extern void check_default_allows_bound(Relation parent, Relation defaultRel,
|
||||
PartitionBoundSpec *new_spec);
|
||||
extern void check_default_partition_contents(Relation parent,
|
||||
Relation defaultRel,
|
||||
PartitionBoundSpec *new_spec);
|
||||
|
||||
extern PartitionRangeBound *make_one_range_bound(PartitionKey key, int index,
|
||||
List *datums, bool lower);
|
||||
extern PartitionRangeBound *make_one_partition_rbound(PartitionKey key, int index,
|
||||
List *datums, bool lower);
|
||||
extern int32 partition_hbound_cmp(int modulus1, int remainder1, int modulus2,
|
||||
int remainder2);
|
||||
extern int32 partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,
|
||||
|
Loading…
x
Reference in New Issue
Block a user