From 19832753f1bb052c5fe10328939b670507df7a93 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 13 Jun 2018 13:18:02 -0400 Subject: [PATCH] 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. --- src/backend/commands/tablecmds.c | 2 +- src/backend/executor/execPartition.c | 27 +++++++++++++++------------ src/backend/partitioning/partbounds.c | 23 ++++++++++++----------- src/backend/partitioning/partprune.c | 3 ++- src/backend/utils/cache/partcache.c | 8 ++++---- src/include/partitioning/partbounds.h | 13 +++++++------ 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index d20991a1e5..8b848f91a7 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -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); } diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index 4eeee7c5e7..7a4665cc4e 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -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; } diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index 09c7c3e252..b19c76acc8 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -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; diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 480b22e043..c31cd4f945 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -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 = diff --git a/src/backend/utils/cache/partcache.c b/src/backend/utils/cache/partcache.c index 833246ee87..115a9fe78f 100644 --- a/src/backend/utils/cache/partcache.c +++ b/src/backend/utils/cache/partcache.c @@ -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++; diff --git a/src/include/partitioning/partbounds.h b/src/include/partitioning/partbounds.h index 71c04aa446..c7535e32fc 100644 --- a/src/include/partitioning/partbounds.h +++ b/src/include/partitioning/partbounds.h @@ -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,