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))
|
if (OidIsValid(defaultPartOid))
|
||||||
{
|
{
|
||||||
check_default_allows_bound(parent, defaultRel, bound);
|
check_default_partition_contents(parent, defaultRel, bound);
|
||||||
/* Keep the lock until commit. */
|
/* Keep the lock until commit. */
|
||||||
heap_close(defaultRel, NoLock);
|
heap_close(defaultRel, NoLock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1085,17 +1085,20 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||||
int part_index = -1;
|
int part_index = -1;
|
||||||
PartitionKey key = RelationGetPartitionKey(relation);
|
PartitionKey key = RelationGetPartitionKey(relation);
|
||||||
PartitionDesc partdesc = RelationGetPartitionDesc(relation);
|
PartitionDesc partdesc = RelationGetPartitionDesc(relation);
|
||||||
|
PartitionBoundInfo boundinfo = partdesc->boundinfo;
|
||||||
|
|
||||||
/* Route as appropriate based on partitioning strategy. */
|
/* Route as appropriate based on partitioning strategy. */
|
||||||
switch (key->strategy)
|
switch (key->strategy)
|
||||||
{
|
{
|
||||||
case PARTITION_STRATEGY_HASH:
|
case PARTITION_STRATEGY_HASH:
|
||||||
{
|
{
|
||||||
PartitionBoundInfo boundinfo = partdesc->boundinfo;
|
int greatest_modulus;
|
||||||
int greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
uint64 rowHash;
|
||||||
uint64 rowHash = compute_hash_value(key->partnatts,
|
|
||||||
key->partsupfunc,
|
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
||||||
values, isnull);
|
rowHash = compute_partition_hash_value(key->partnatts,
|
||||||
|
key->partsupfunc,
|
||||||
|
values, isnull);
|
||||||
|
|
||||||
part_index = boundinfo->indexes[rowHash % greatest_modulus];
|
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:
|
case PARTITION_STRATEGY_LIST:
|
||||||
if (isnull[0])
|
if (isnull[0])
|
||||||
{
|
{
|
||||||
if (partition_bound_accepts_nulls(partdesc->boundinfo))
|
if (partition_bound_accepts_nulls(boundinfo))
|
||||||
part_index = partdesc->boundinfo->null_index;
|
part_index = boundinfo->null_index;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1113,10 +1116,10 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||||
|
|
||||||
bound_offset = partition_list_bsearch(key->partsupfunc,
|
bound_offset = partition_list_bsearch(key->partsupfunc,
|
||||||
key->partcollation,
|
key->partcollation,
|
||||||
partdesc->boundinfo,
|
boundinfo,
|
||||||
values[0], &equal);
|
values[0], &equal);
|
||||||
if (bound_offset >= 0 && equal)
|
if (bound_offset >= 0 && equal)
|
||||||
part_index = partdesc->boundinfo->indexes[bound_offset];
|
part_index = boundinfo->indexes[bound_offset];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1143,7 +1146,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||||
{
|
{
|
||||||
bound_offset = partition_range_datum_bsearch(key->partsupfunc,
|
bound_offset = partition_range_datum_bsearch(key->partsupfunc,
|
||||||
key->partcollation,
|
key->partcollation,
|
||||||
partdesc->boundinfo,
|
boundinfo,
|
||||||
key->partnatts,
|
key->partnatts,
|
||||||
values,
|
values,
|
||||||
&equal);
|
&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
|
* bound of the partition we're looking for, if there
|
||||||
* actually exists one.
|
* actually exists one.
|
||||||
*/
|
*/
|
||||||
part_index = partdesc->boundinfo->indexes[bound_offset + 1];
|
part_index = boundinfo->indexes[bound_offset + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1169,7 +1172,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
|
||||||
* the default partition, if there is one.
|
* the default partition, if there is one.
|
||||||
*/
|
*/
|
||||||
if (part_index < 0)
|
if (part_index < 0)
|
||||||
part_index = partdesc->boundinfo->default_index;
|
part_index = boundinfo->default_index;
|
||||||
|
|
||||||
return part_index;
|
return part_index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,8 +470,8 @@ check_new_partition_bound(char *relname, Relation parent,
|
||||||
*upper;
|
*upper;
|
||||||
|
|
||||||
Assert(spec->strategy == PARTITION_STRATEGY_RANGE);
|
Assert(spec->strategy == PARTITION_STRATEGY_RANGE);
|
||||||
lower = make_one_range_bound(key, -1, spec->lowerdatums, true);
|
lower = make_one_partition_rbound(key, -1, spec->lowerdatums, true);
|
||||||
upper = make_one_range_bound(key, -1, spec->upperdatums, false);
|
upper = make_one_partition_rbound(key, -1, spec->upperdatums, false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* First check if the resulting range would be empty with
|
* 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
|
* 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,
|
* would properly belong to the new partition being added. If it finds one,
|
||||||
* it throws an error.
|
* it throws an error.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
check_default_allows_bound(Relation parent, Relation default_rel,
|
check_default_partition_contents(Relation parent, Relation default_rel,
|
||||||
PartitionBoundSpec *new_spec)
|
PartitionBoundSpec *new_spec)
|
||||||
{
|
{
|
||||||
List *new_part_constraints;
|
List *new_part_constraints;
|
||||||
List *def_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
|
* Return a PartitionRangeBound given a list of PartitionRangeDatum elements
|
||||||
* and a flag telling whether the bound is lower or not. Made into a function
|
* 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.
|
* because there are multiple sites that want to use this facility.
|
||||||
*/
|
*/
|
||||||
PartitionRangeBound *
|
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;
|
PartitionRangeBound *bound;
|
||||||
ListCell *lc;
|
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
|
uint64
|
||||||
compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||||
Datum *values, bool *isnull)
|
Datum *values, bool *isnull)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint64 rowHash = 0;
|
uint64 rowHash = 0;
|
||||||
|
@ -2066,6 +2066,7 @@ compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||||
|
|
||||||
for (i = 0; i < partnatts; i++)
|
for (i = 0; i < partnatts; i++)
|
||||||
{
|
{
|
||||||
|
/* Nulls are just ignored */
|
||||||
if (!isnull[i])
|
if (!isnull[i])
|
||||||
{
|
{
|
||||||
Datum hash;
|
Datum hash;
|
||||||
|
|
|
@ -2018,7 +2018,8 @@ get_matching_hash_bounds(PartitionPruneContext *context,
|
||||||
isnull[i] = bms_is_member(i, nullkeys);
|
isnull[i] = bms_is_member(i, nullkeys);
|
||||||
|
|
||||||
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
|
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)
|
if (partindices[rowHash % greatest_modulus] >= 0)
|
||||||
result->bound_offsets =
|
result->bound_offsets =
|
||||||
|
|
|
@ -499,10 +499,10 @@ RelationBuildPartitionDesc(Relation rel)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lower = make_one_range_bound(key, i, spec->lowerdatums,
|
lower = make_one_partition_rbound(key, i, spec->lowerdatums,
|
||||||
true);
|
true);
|
||||||
upper = make_one_range_bound(key, i, spec->upperdatums,
|
upper = make_one_partition_rbound(key, i, spec->upperdatums,
|
||||||
false);
|
false);
|
||||||
all_bounds[ndatums++] = lower;
|
all_bounds[ndatums++] = lower;
|
||||||
all_bounds[ndatums++] = upper;
|
all_bounds[ndatums++] = upper;
|
||||||
i++;
|
i++;
|
||||||
|
|
|
@ -105,8 +105,8 @@ typedef struct PartitionRangeBound
|
||||||
} PartitionRangeBound;
|
} PartitionRangeBound;
|
||||||
|
|
||||||
extern int get_hash_partition_greatest_modulus(PartitionBoundInfo b);
|
extern int get_hash_partition_greatest_modulus(PartitionBoundInfo b);
|
||||||
extern uint64 compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
|
||||||
Datum *values, bool *isnull);
|
Datum *values, bool *isnull);
|
||||||
extern List *get_qual_from_partbound(Relation rel, Relation parent,
|
extern List *get_qual_from_partbound(Relation rel, Relation parent,
|
||||||
PartitionBoundSpec *spec);
|
PartitionBoundSpec *spec);
|
||||||
extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
|
extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
|
||||||
|
@ -116,11 +116,12 @@ extern PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src,
|
||||||
PartitionKey key);
|
PartitionKey key);
|
||||||
extern void check_new_partition_bound(char *relname, Relation parent,
|
extern void check_new_partition_bound(char *relname, Relation parent,
|
||||||
PartitionBoundSpec *spec);
|
PartitionBoundSpec *spec);
|
||||||
extern void check_default_allows_bound(Relation parent, Relation defaultRel,
|
extern void check_default_partition_contents(Relation parent,
|
||||||
PartitionBoundSpec *new_spec);
|
Relation defaultRel,
|
||||||
|
PartitionBoundSpec *new_spec);
|
||||||
|
|
||||||
extern PartitionRangeBound *make_one_range_bound(PartitionKey key, int index,
|
extern PartitionRangeBound *make_one_partition_rbound(PartitionKey key, int index,
|
||||||
List *datums, bool lower);
|
List *datums, bool lower);
|
||||||
extern int32 partition_hbound_cmp(int modulus1, int remainder1, int modulus2,
|
extern int32 partition_hbound_cmp(int modulus1, int remainder1, int modulus2,
|
||||||
int remainder2);
|
int remainder2);
|
||||||
extern int32 partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,
|
extern int32 partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,
|
||||||
|
|
Loading…
Reference in New Issue