Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf1dae09

Browse files
committed
Clarify the contract of partition_rbound_cmp().
partition_rbound_cmp() is intended to compare range partition boundsin a way such that if all the bound values are equal but one is anupper bound and one is a lower bound, the upper bound is treated assmaller than the lower bound. This particular ordering is required byRelationBuildPartitionDesc() when building the PartitionBoundInfoData,so that it can consistently keep only the upper bounds when upper andlower bounds coincide.Update the function comment to make that clearer.Also, fix a (currently unreachable) corner-case bug -- if the boundvalues coincide and they contain unbounded values, fall through to thelower-vs-upper comparison code, rather than immediately returning0. Currently it is not possible to define coincident upper and lowerbounds containing unbounded columns, but that may change in thefuture, so code defensively.Discussion:https://postgr.es/m/CAAJ_b947mowpLdxL3jo3YLKngRjrq9+Ej4ymduQTfYR+8=YAYQ@mail.gmail.com
1 parentc03911d commitf1dae09

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

‎src/backend/catalog/partition.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
*
5858
* In the case of range partitioning, ndatums will typically be far less than
5959
* 2 * nparts, because a partition's upper bound and the next partition's lower
60-
* bound are the same in most common cases, and we only store one of them.
60+
* bound are the same in most common cases, and we only store one of them (the
61+
* upper bound).
6162
*
6263
* In the case of list partitioning, the indexes array stores one entry for
6364
* every datum, which is the index of the partition that accepts a given datum.
@@ -2136,7 +2137,14 @@ qsort_partition_rbound_cmp(const void *a, const void *b, void *arg)
21362137
* partition_rbound_cmp
21372138
*
21382139
* Return for two range bounds whether the 1st one (specified in datum1,
2139-
* content1, and lower1) is <=, =, >= the bound specified in *b2
2140+
* content1, and lower1) is <, =, or > the bound specified in *b2.
2141+
*
2142+
* Note that if the values of the two range bounds compare equal, then we take
2143+
* into account whether they are upper or lower bounds, and an upper bound is
2144+
* considered to be smaller than a lower bound. This is important to the way
2145+
* that RelationBuildPartitionDesc() builds the PartitionBoundInfoData
2146+
* structure, which only stores the upper bound of a common boundary between
2147+
* two contiguous partitions.
21402148
*/
21412149
staticint32
21422150
partition_rbound_cmp(PartitionKeykey,
@@ -2152,22 +2160,30 @@ partition_rbound_cmp(PartitionKey key,
21522160
for (i=0;i<key->partnatts;i++)
21532161
{
21542162
/*
2155-
* First, handle cases involving infinity, which don't require
2156-
* invoking the comparison proc.
2163+
* First, handle cases where the column is unbounded, which should not
2164+
* invoke the comparison procedure, and should not consider any later
2165+
* columns.
21572166
*/
2158-
if (content1[i]!=RANGE_DATUM_FINITE&&
2167+
if (content1[i]!=RANGE_DATUM_FINITE||
21592168
content2[i]!=RANGE_DATUM_FINITE)
2160-
2169+
{
21612170
/*
2162-
*Both are infinity, so theyare equal unless one is negative
2163-
*infinity and other positive (orvice versa)
2171+
*If the bound valuesare equal, fall through and compare whether
2172+
*they are upperorlower bounds.
21642173
*/
2165-
returncontent1[i]==content2[i] ?0
2166-
: (content1[i]<content2[i] ?-1 :1);
2167-
elseif (content1[i]!=RANGE_DATUM_FINITE)
2168-
returncontent1[i]==RANGE_DATUM_NEG_INF ?-1 :1;
2169-
elseif (content2[i]!=RANGE_DATUM_FINITE)
2170-
returncontent2[i]==RANGE_DATUM_NEG_INF ?1 :-1;
2174+
if (content1[i]==content2[i])
2175+
break;
2176+
2177+
/* Otherwise, one bound is definitely larger than the other */
2178+
if (content1[i]==RANGE_DATUM_NEG_INF)
2179+
return-1;
2180+
elseif (content1[i]==RANGE_DATUM_POS_INF)
2181+
return1;
2182+
elseif (content2[i]==RANGE_DATUM_NEG_INF)
2183+
return1;
2184+
elseif (content2[i]==RANGE_DATUM_POS_INF)
2185+
return-1;
2186+
}
21712187

21722188
cmpval=DatumGetInt32(FunctionCall2Coll(&key->partsupfunc[i],
21732189
key->partcollation[i],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp