diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 354eb0d4e6..8c024773af 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -2048,8 +2048,12 @@ get_matching_hash_bounds(PartitionPruneContext *context, bms_make_singleton(rowHash % greatest_modulus); } else + { + /* Getting here means at least one hash partition exists. */ + Assert(boundinfo->ndatums > 0); result->bound_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); + } /* * There is neither a special hash null partition or the default hash @@ -2995,7 +2999,11 @@ perform_pruning_combine_step(PartitionPruneContext *context, { PartitionBoundInfo boundinfo = context->boundinfo; - result->bound_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); + if (boundinfo->ndatums > 0) + result->bound_offsets = bms_add_range(NULL, 0, + boundinfo->ndatums - 1); + else + result->bound_offsets = NULL; result->scan_default = partition_bound_has_default(boundinfo); result->scan_null = partition_bound_accepts_nulls(boundinfo); return result;