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