Skip to content

Commit 236d6d4

Browse files
committed
Remove redundant has_null member from PartitionBoundInfoData.
Jeevan Ladhe, with some changes by me. Discussion: http://postgr.es/m/CAOgcT0NZ_30-pjBpW2OgneV1ammArHkZDZ8B_KFC3q+_Xb2H9A@mail.gmail.com
1 parent 3db2279 commit 236d6d4

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/backend/catalog/partition.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* Information about bounds of a partitioned relation
5454
*
5555
* A list partition datum that is known to be NULL is never put into the
56-
* datums array. Instead, it is tracked using has_null and null_index fields.
56+
* datums array. Instead, it is tracked using the null_index field.
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
@@ -86,12 +86,12 @@ typedef struct PartitionBoundInfoData
8686
int *indexes; /* Partition indexes; one entry per member of
8787
* the datums array (plus one if range
8888
* partitioned table) */
89-
bool has_null; /* Is there a null-accepting partition? false
90-
* for range partitioned tables */
9189
int null_index; /* Index of the null-accepting partition; -1
92-
* for range partitioned tables */
90+
* if there isn't one */
9391
} PartitionBoundInfoData;
9492

93+
#define partition_bound_accepts_nulls(bi) ((bi)->null_index != -1)
94+
9595
/*
9696
* When qsort'ing partition bounds after reading from the catalog, each bound
9797
* is represented with one of the following structs.
@@ -173,7 +173,6 @@ RelationBuildPartitionDesc(Relation rel)
173173

174174
/* List partitioning specific */
175175
PartitionListValue **all_values = NULL;
176-
bool found_null = false;
177176
int null_index = -1;
178177

179178
/* Range partitioning specific */
@@ -245,7 +244,6 @@ RelationBuildPartitionDesc(Relation rel)
245244
* Create a unified list of non-null values across all partitions.
246245
*/
247246
i = 0;
248-
found_null = false;
249247
null_index = -1;
250248
foreach(cell, boundspecs)
251249
{
@@ -274,9 +272,8 @@ RelationBuildPartitionDesc(Relation rel)
274272
* instead for the code further down below where we
275273
* construct the actual relcache struct.
276274
*/
277-
if (found_null)
275+
if (null_index != -1)
278276
elog(ERROR, "found null more than once");
279-
found_null = true;
280277
null_index = i;
281278
}
282279

@@ -466,7 +463,6 @@ RelationBuildPartitionDesc(Relation rel)
466463
{
467464
case PARTITION_STRATEGY_LIST:
468465
{
469-
boundinfo->has_null = found_null;
470466
boundinfo->indexes = (int *) palloc(ndatums * sizeof(int));
471467

472468
/*
@@ -498,20 +494,18 @@ RelationBuildPartitionDesc(Relation rel)
498494
* accepts only null and hence not covered in the above
499495
* loop which only handled non-null values.
500496
*/
501-
if (found_null)
497+
if (null_index != -1)
502498
{
503499
Assert(null_index >= 0);
504500
if (mapping[null_index] == -1)
505501
mapping[null_index] = next_index++;
502+
boundinfo->null_index = mapping[null_index];
506503
}
504+
else
505+
boundinfo->null_index = -1;
507506

508507
/* All partition must now have a valid mapping */
509508
Assert(next_index == nparts);
510-
511-
if (found_null)
512-
boundinfo->null_index = mapping[null_index];
513-
else
514-
boundinfo->null_index = -1;
515509
break;
516510
}
517511

@@ -611,9 +605,6 @@ partition_bounds_equal(PartitionKey key,
611605
if (b1->ndatums != b2->ndatums)
612606
return false;
613607

614-
if (b1->has_null != b2->has_null)
615-
return false;
616-
617608
if (b1->null_index != b2->null_index)
618609
return false;
619610

@@ -696,7 +687,8 @@ check_new_partition_bound(char *relname, Relation parent, Node *bound)
696687

697688
Assert(boundinfo &&
698689
boundinfo->strategy == PARTITION_STRATEGY_LIST &&
699-
(boundinfo->ndatums > 0 || boundinfo->has_null));
690+
(boundinfo->ndatums > 0 ||
691+
partition_bound_accepts_nulls(boundinfo)));
700692

701693
foreach(cell, spec->listdatums)
702694
{
@@ -717,7 +709,7 @@ check_new_partition_bound(char *relname, Relation parent, Node *bound)
717709
break;
718710
}
719711
}
720-
else if (boundinfo->has_null)
712+
else if (partition_bound_accepts_nulls(boundinfo))
721713
{
722714
overlap = true;
723715
with = boundinfo->null_index;
@@ -1985,7 +1977,7 @@ get_partition_for_tuple(PartitionDispatch *pd,
19851977
* partition exists.
19861978
*/
19871979
cur_index = -1;
1988-
if (isnull[0] && partdesc->boundinfo->has_null)
1980+
if (isnull[0] && partition_bound_accepts_nulls(partdesc->boundinfo))
19891981
cur_index = partdesc->boundinfo->null_index;
19901982
else if (!isnull[0])
19911983
{

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