diff --git a/src/backend/catalog/partition.c b/src/backend/catalog/partition.c index 363b12836b..79cda9cecd 100644 --- a/src/backend/catalog/partition.c +++ b/src/backend/catalog/partition.c @@ -1673,9 +1673,9 @@ get_matching_partitions(PartitionPruneContext *context, /* * Allocate space for individual pruning steps to store its result. Each * slot will hold a PruneStepResult after performing a given pruning step. - * Later steps may use the result of one or more earlier steps. Result of - * of applying all pruning steps is the value contained in the slot of the - * last pruning step. + * Later steps may use the result of one or more earlier steps. The + * result of applying all pruning steps is the value contained in the slot + * of the last pruning step. */ step_results = (PruneStepResult **) palloc0(num_steps * sizeof(PruneStepResult *)); @@ -1705,10 +1705,9 @@ get_matching_partitions(PartitionPruneContext *context, } /* - * At this point we know that offsets of all the datums whose - * corresponding partitions need to be in the result, including special - * null-accepting and default partitions. Collect the actual partition - * indexes now. + * At this point we know the offsets of all the datums whose corresponding + * partitions need to be in the result, including special null-accepting + * and default partitions. Collect the actual partition indexes now. */ i = -1; result = NULL; @@ -1819,7 +1818,9 @@ perform_pruning_base_step(PartitionPruneContext *context, if (cmpfn != context->partsupfunc[keyno].fn_oid) fmgr_info(cmpfn, &partsupfunc[keyno]); else - partsupfunc[keyno] = context->partsupfunc[keyno]; + fmgr_info_copy(&partsupfunc[keyno], + &context->partsupfunc[keyno], + CurrentMemoryContext); values[keyno] = datum; nvalues++; @@ -1985,11 +1986,11 @@ perform_pruning_combine_step(PartitionPruneContext *context, source = step_results[source_step_id]; Assert(source != NULL); - /* First add possible datum offsets. */ + /* First add all possible datum offsets. */ result->datum_offsets = bms_add_range(NULL, 0, boundinfo->ndatums - 1); - /* Then remove from it those present in the source. */ + /* Then remove the members present in source. */ result->datum_offsets = bms_del_members(result->datum_offsets, source->datum_offsets); @@ -2037,7 +2038,7 @@ partkey_datum_from_expr(PartitionPruneContext *context, * Determine offset of the hash bound matching the specified value, * considering that all the non-null values come from clauses containing * a compatible hash eqaulity operator and any keys that are null come - * from a IS NULL clause + * from an IS NULL clause * * In most cases, the result would contain just one bound's offset, although * the set may be empty if the corresponding hash partition has not been @@ -2149,17 +2150,10 @@ get_matching_list_bounds(PartitionPruneContext *context, * the former doesn't exist. */ if (partition_bound_accepts_nulls(boundinfo)) - { result->scan_null = true; - return result; - } else if (partition_bound_has_default(boundinfo)) - { result->scan_default = true; - return result; - } - else - return result; + return result; } /* @@ -2335,7 +2329,7 @@ get_matching_range_bounds(PartitionPruneContext *context, result = (PruneStepResult *) palloc0(sizeof(PruneStepResult)); /* - * If there are no datums to compare keys with, or if we got a IS NULL + * If there are no datums to compare keys with, or if we got an IS NULL * clause just return the default partition, if it exists. */ if (boundinfo->ndatums == 0 || !bms_is_empty(nullkeys)) @@ -2506,8 +2500,13 @@ get_matching_range_bounds(PartitionPruneContext *context, if (partition_bound_has_default(boundinfo)) { for (i = minoff; i <= maxoff; i++) + { if (partindices[i] < 0) + { result->scan_default = true; + break; + } + } } Assert(minoff >= 0 && maxoff >= 0); @@ -2517,24 +2516,17 @@ get_matching_range_bounds(PartitionPruneContext *context, else if (off >= 0) /* !is_equal */ { /* - * Look-up value falls in the range between some bounds in - * boundinfo. off would be the offset of the greatest + * The look-up value falls in the range between some bounds in + * boundinfo. 'off' would be the offset of the greatest * bound that is <= look-up value, so add off + 1 to the * result instead as the offset of the upper bound of the * only partition that may contain the look-up value. */ if (partindices[off + 1] >= 0) - { result->datum_offsets = bms_make_singleton(off + 1); - return result; - } else if (partition_bound_has_default(boundinfo)) - { result->scan_default = true; - return result; - } - else - return result; + return result; } /* * off < 0, meaning the look-up value is smaller that all bounds, @@ -2683,8 +2675,8 @@ get_matching_range_bounds(PartitionPruneContext *context, maxoff = inclusive ? off + 1: off; } /* - * Look-up value falls in the range between some bounds in - * boundinfo. off would be the offset of the greatest + * The look-up value falls in the range between some bounds in + * boundinfo. 'off' would be the offset of the greatest * bound that is <= look-up value, so add off + 1 to the * result instead as the offset of the upper bound of the * greatest partition that may contain look-up value. If diff --git a/src/backend/optimizer/util/partprune.c b/src/backend/optimizer/util/partprune.c index 48fdeacac3..2dd4a3ecf3 100644 --- a/src/backend/optimizer/util/partprune.c +++ b/src/backend/optimizer/util/partprune.c @@ -254,7 +254,7 @@ generate_partition_pruning_steps(RelOptInfo *rel, List *clauses, * If when going through clauses, we find any that are marked as pseudoconstant * and contains a constant false value, we stop generating any further steps * and simply return NIL (that is, no pruning steps) after setting *constfalse - * to true. Caller should consider all partitions as pruned in that case. + * to true. The caller should consider all partitions as pruned in that case. * We may do the same if we find that mutually contradictory clauses are * present, but were not turned into a pseudoconstant at higher levels. * @@ -593,7 +593,7 @@ generate_partition_pruning_steps_internal(RelOptInfo *rel, unionStep = (PartitionPruneStep *) generate_pruning_step_combine(context, step_ids, COMBINE_UNION); - /* Then slap on a DIFFERENCE combine step. */ + /* Now add a step to invert the results. */ diffStep = (PartitionPruneStep *) generate_pruning_step_combine(context, list_make1_int(unionStep->step_id), @@ -603,7 +603,7 @@ generate_partition_pruning_steps_internal(RelOptInfo *rel, } /* - * generate_opsteps set to false means no OpExprs were directly presemt in + * generate_opsteps set to false means no OpExprs were directly present in * the input list. */ if (!generate_opsteps) @@ -802,8 +802,8 @@ generate_pruning_steps_from_opexprs(PartitionScheme part_scheme, } /* - * If we've decided that clauses for subsequent partition keys would't - * be useful for pruning, don't look. + * If we've decided that clauses for subsequent partition keys + * wouldn't be useful for pruning, don't look. */ if (!consider_next_key) break;