Skip to content

Commit 1983275

Browse files
committed
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.
1 parent e23bae8 commit 1983275

File tree

6 files changed

+41
-35
lines changed

6 files changed

+41
-35
lines changed

src/backend/commands/tablecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
855855
*/
856856
if (OidIsValid(defaultPartOid))
857857
{
858-
check_default_allows_bound(parent, defaultRel, bound);
858+
check_default_partition_contents(parent, defaultRel, bound);
859859
/* Keep the lock until commit. */
860860
heap_close(defaultRel, NoLock);
861861
}

src/backend/executor/execPartition.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,17 +1085,20 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
10851085
int part_index = -1;
10861086
PartitionKey key = RelationGetPartitionKey(relation);
10871087
PartitionDesc partdesc = RelationGetPartitionDesc(relation);
1088+
PartitionBoundInfo boundinfo = partdesc->boundinfo;
10881089

10891090
/* Route as appropriate based on partitioning strategy. */
10901091
switch (key->strategy)
10911092
{
10921093
case PARTITION_STRATEGY_HASH:
10931094
{
1094-
PartitionBoundInfo boundinfo = partdesc->boundinfo;
1095-
int greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
1096-
uint64 rowHash = compute_hash_value(key->partnatts,
1097-
key->partsupfunc,
1098-
values, isnull);
1095+
int greatest_modulus;
1096+
uint64 rowHash;
1097+
1098+
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
1099+
rowHash = compute_partition_hash_value(key->partnatts,
1100+
key->partsupfunc,
1101+
values, isnull);
10991102

11001103
part_index = boundinfo->indexes[rowHash % greatest_modulus];
11011104
}
@@ -1104,19 +1107,19 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
11041107
case PARTITION_STRATEGY_LIST:
11051108
if (isnull[0])
11061109
{
1107-
if (partition_bound_accepts_nulls(partdesc->boundinfo))
1108-
part_index = partdesc->boundinfo->null_index;
1110+
if (partition_bound_accepts_nulls(boundinfo))
1111+
part_index = boundinfo->null_index;
11091112
}
11101113
else
11111114
{
11121115
bool equal = false;
11131116

11141117
bound_offset = partition_list_bsearch(key->partsupfunc,
11151118
key->partcollation,
1116-
partdesc->boundinfo,
1119+
boundinfo,
11171120
values[0], &equal);
11181121
if (bound_offset >= 0 && equal)
1119-
part_index = partdesc->boundinfo->indexes[bound_offset];
1122+
part_index = boundinfo->indexes[bound_offset];
11201123
}
11211124
break;
11221125

@@ -1143,7 +1146,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
11431146
{
11441147
bound_offset = partition_range_datum_bsearch(key->partsupfunc,
11451148
key->partcollation,
1146-
partdesc->boundinfo,
1149+
boundinfo,
11471150
key->partnatts,
11481151
values,
11491152
&equal);
@@ -1154,7 +1157,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
11541157
* bound of the partition we're looking for, if there
11551158
* actually exists one.
11561159
*/
1157-
part_index = partdesc->boundinfo->indexes[bound_offset + 1];
1160+
part_index = boundinfo->indexes[bound_offset + 1];
11581161
}
11591162
}
11601163
break;
@@ -1169,7 +1172,7 @@ get_partition_for_tuple(Relation relation, Datum *values, bool *isnull)
11691172
* the default partition, if there is one.
11701173
*/
11711174
if (part_index < 0)
1172-
part_index = partdesc->boundinfo->default_index;
1175+
part_index = boundinfo->default_index;
11731176

11741177
return part_index;
11751178
}

src/backend/partitioning/partbounds.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,8 @@ check_new_partition_bound(char *relname, Relation parent,
470470
*upper;
471471

472472
Assert(spec->strategy == PARTITION_STRATEGY_RANGE);
473-
lower = make_one_range_bound(key, -1, spec->lowerdatums, true);
474-
upper = make_one_range_bound(key, -1, spec->upperdatums, false);
473+
lower = make_one_partition_rbound(key, -1, spec->lowerdatums, true);
474+
upper = make_one_partition_rbound(key, -1, spec->upperdatums, false);
475475

476476
/*
477477
* First check if the resulting range would be empty with
@@ -589,15 +589,15 @@ check_new_partition_bound(char *relname, Relation parent,
589589
}
590590

591591
/*
592-
* check_default_allows_bound
592+
* check_default_partition_contents
593593
*
594594
* This function checks if there exists a row in the default partition that
595595
* would properly belong to the new partition being added. If it finds one,
596596
* it throws an error.
597597
*/
598598
void
599-
check_default_allows_bound(Relation parent, Relation default_rel,
600-
PartitionBoundSpec *new_spec)
599+
check_default_partition_contents(Relation parent, Relation default_rel,
600+
PartitionBoundSpec *new_spec)
601601
{
602602
List *new_part_constraints;
603603
List *def_part_constraints;
@@ -757,14 +757,14 @@ get_hash_partition_greatest_modulus(PartitionBoundInfo bound)
757757
}
758758

759759
/*
760-
* make_one_range_bound
760+
* make_one_partition_rbound
761761
*
762762
* Return a PartitionRangeBound given a list of PartitionRangeDatum elements
763763
* and a flag telling whether the bound is lower or not. Made into a function
764764
* because there are multiple sites that want to use this facility.
765765
*/
766766
PartitionRangeBound *
767-
make_one_range_bound(PartitionKey key, int index, List *datums, bool lower)
767+
make_one_partition_rbound(PartitionKey key, int index, List *datums, bool lower)
768768
{
769769
PartitionRangeBound *bound;
770770
ListCell *lc;
@@ -2052,20 +2052,21 @@ get_range_nulltest(PartitionKey key)
20522052
}
20532053

20542054
/*
2055-
* compute_hash_value
2055+
* compute_partition_hash_value
20562056
*
2057-
* Compute the hash value for given not null partition key values.
2057+
* Compute the hash value for given partition key values.
20582058
*/
20592059
uint64
2060-
compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
2061-
Datum *values, bool *isnull)
2060+
compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
2061+
Datum *values, bool *isnull)
20622062
{
20632063
int i;
20642064
uint64 rowHash = 0;
20652065
Datum seed = UInt64GetDatum(HASH_PARTITION_SEED);
20662066

20672067
for (i = 0; i < partnatts; i++)
20682068
{
2069+
/* Nulls are just ignored */
20692070
if (!isnull[i])
20702071
{
20712072
Datum hash;

src/backend/partitioning/partprune.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,8 @@ get_matching_hash_bounds(PartitionPruneContext *context,
20182018
isnull[i] = bms_is_member(i, nullkeys);
20192019

20202020
greatest_modulus = get_hash_partition_greatest_modulus(boundinfo);
2021-
rowHash = compute_hash_value(partnatts, partsupfunc, values, isnull);
2021+
rowHash = compute_partition_hash_value(partnatts, partsupfunc,
2022+
values, isnull);
20222023

20232024
if (partindices[rowHash % greatest_modulus] >= 0)
20242025
result->bound_offsets =

src/backend/utils/cache/partcache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,10 @@ RelationBuildPartitionDesc(Relation rel)
499499
continue;
500500
}
501501

502-
lower = make_one_range_bound(key, i, spec->lowerdatums,
503-
true);
504-
upper = make_one_range_bound(key, i, spec->upperdatums,
505-
false);
502+
lower = make_one_partition_rbound(key, i, spec->lowerdatums,
503+
true);
504+
upper = make_one_partition_rbound(key, i, spec->upperdatums,
505+
false);
506506
all_bounds[ndatums++] = lower;
507507
all_bounds[ndatums++] = upper;
508508
i++;

src/include/partitioning/partbounds.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ typedef struct PartitionRangeBound
105105
} PartitionRangeBound;
106106

107107
extern int get_hash_partition_greatest_modulus(PartitionBoundInfo b);
108-
extern uint64 compute_hash_value(int partnatts, FmgrInfo *partsupfunc,
109-
Datum *values, bool *isnull);
108+
extern uint64 compute_partition_hash_value(int partnatts, FmgrInfo *partsupfunc,
109+
Datum *values, bool *isnull);
110110
extern List *get_qual_from_partbound(Relation rel, Relation parent,
111111
PartitionBoundSpec *spec);
112112
extern bool partition_bounds_equal(int partnatts, int16 *parttyplen,
@@ -116,11 +116,12 @@ extern PartitionBoundInfo partition_bounds_copy(PartitionBoundInfo src,
116116
PartitionKey key);
117117
extern void check_new_partition_bound(char *relname, Relation parent,
118118
PartitionBoundSpec *spec);
119-
extern void check_default_allows_bound(Relation parent, Relation defaultRel,
120-
PartitionBoundSpec *new_spec);
119+
extern void check_default_partition_contents(Relation parent,
120+
Relation defaultRel,
121+
PartitionBoundSpec *new_spec);
121122

122-
extern PartitionRangeBound *make_one_range_bound(PartitionKey key, int index,
123-
List *datums, bool lower);
123+
extern PartitionRangeBound *make_one_partition_rbound(PartitionKey key, int index,
124+
List *datums, bool lower);
124125
extern int32 partition_hbound_cmp(int modulus1, int remainder1, int modulus2,
125126
int remainder2);
126127
extern int32 partition_rbound_cmp(int partnatts, FmgrInfo *partsupfunc,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy