diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index a892ca1aea..cf9bbe8b05 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -179,7 +179,9 @@ static PruneStepResult *get_matching_range_bounds(PartitionPruneContext *context FmgrInfo *partsupfunc, Bitmapset *nullkeys); static Bitmapset *pull_exec_paramids(Expr *expr); static bool pull_exec_paramids_walker(Node *node, Bitmapset **context); +#ifdef NOT_USED static Bitmapset *get_partkey_exec_paramids(List *steps); +#endif static PruneStepResult *perform_pruning_base_step(PartitionPruneContext *context, PartitionPruneStepOp *opstep); static PruneStepResult *perform_pruning_combine_step(PartitionPruneContext *context, @@ -308,6 +310,51 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, return pruneinfo; } +typedef struct +{ + Bitmapset **extern_params; + Bitmapset **exec_params; +} need_runtime_prune_context; + +static bool +need_runtime_prune_walker(Node *node, need_runtime_prune_context *context) +{ + if (node == NULL) + return false; + + if (IsA(node, Param)) + { + Param *param = (Param *) node; + + if (param->paramkind == PARAM_EXEC) + *context->exec_params = + bms_add_member(*context->exec_params, param->paramid); + else if (param->paramkind == PARAM_EXTERN) + *context->extern_params = + bms_add_member(*context->extern_params, param->paramid); + return false; + } + + return expression_tree_walker(node, need_runtime_prune_walker, + (void *) context); +} + +static void +need_runtime_prune(Node *clauses, + Bitmapset **init_paramids, + Bitmapset **exec_paramids, + bool *mut_exprs_found) +{ + need_runtime_prune_context context; + + *mut_exprs_found = contain_mutable_functions(clauses); + + context.extern_params = init_paramids; + context.exec_params = exec_paramids; + + need_runtime_prune_walker(clauses, &context); +} + /* * make_partitionedrel_pruneinfo * Build a List of PartitionedRelPruneInfos, one for each partitioned @@ -357,8 +404,11 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *subpart = find_base_rel(root, rti); PartitionedRelPruneInfo *pinfo; List *partprunequal; - List *initial_pruning_steps; - List *exec_pruning_steps; + Bitmapset *init_paramids = NULL; + Bitmapset *exec_paramids = NULL; + bool mut_exprs_found = false; + List *initial_pruning_steps = NIL; + List *exec_pruning_steps = NIL; bool contradictory; /* @@ -423,14 +473,18 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, targetpart->relids); } - /* - * Convert pruning qual to pruning steps. We need to do this twice, - * once to obtain executor startup pruning steps, and once for - * executor per-scan pruning steps. - */ - initial_pruning_steps = gen_partprune_steps(subpart, partprunequal, - PARTCLAUSE_INITIAL, - &contradictory); + need_runtime_prune((Node *) partprunequal, + &init_paramids, &exec_paramids, &mut_exprs_found); + + if (init_paramids != NULL || mut_exprs_found) + /* + * Convert pruning qual to pruning steps. We need to do this twice, + * once to obtain executor startup pruning steps, and once for + * executor per-scan pruning steps. + */ + initial_pruning_steps = gen_partprune_steps(subpart, partprunequal, + PARTCLAUSE_INITIAL, + &contradictory); if (contradictory) { @@ -446,9 +500,10 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, return NIL; } - exec_pruning_steps = gen_partprune_steps(subpart, partprunequal, - PARTCLAUSE_EXEC, - &contradictory); + if (exec_paramids != NULL) + exec_pruning_steps = gen_partprune_steps(subpart, partprunequal, + PARTCLAUSE_EXEC, + &contradictory); if (contradictory) { @@ -464,7 +519,7 @@ make_partitionedrel_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel, pinfo->rtindex = rti; pinfo->initial_pruning_steps = initial_pruning_steps; pinfo->exec_pruning_steps = exec_pruning_steps; - pinfo->execparamids = get_partkey_exec_paramids(exec_pruning_steps); + pinfo->execparamids = exec_paramids; /* Remaining fields will be filled in the next loop */ pinfolist = lappend(pinfolist, pinfo); @@ -3022,6 +3077,7 @@ pull_exec_paramids_walker(Node *node, Bitmapset **context) (void *) context); } +#ifdef NOT_USED /* * get_partkey_exec_paramids * Loop through given pruning steps and find out which exec Params @@ -3056,6 +3112,7 @@ get_partkey_exec_paramids(List *steps) return execparamids; } +#endif /* * perform_pruning_base_step