diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 58ec2a6..f02bd30 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -2705,6 +2705,9 @@ pull_partkey_params(PartitionPruneInfo *pinfo, List *steps) { Expr *expr = lfirst(lc2); + if (contain_volatile_functions((Node *) expr)) + continue; + if (IsA(expr, Param)) { Param *param = (Param *) expr; @@ -2727,6 +2730,13 @@ pull_partkey_params(PartitionPruneInfo *pinfo, List *steps) } gotone = true; } + else if (!IsA(expr, Const)) + { + Param *param = (Param *) expr; + pinfo->execparams = bms_add_member(pinfo->execparams, + param->paramid); + gotone = true; + } } } @@ -3031,37 +3041,35 @@ static bool partkey_datum_from_expr(PartitionPruneContext *context, Expr *expr, int stateidx, Datum *value) { - switch (nodeTag(expr)) - { - case T_Const: - *value = ((Const *) expr)->constvalue; - return true; - - case T_Param: - - /* - * When being called from the executor we may be able to evaluate - * the Param's value. - */ - if (context->planstate && - bms_is_member(((Param *) expr)->paramid, context->safeparams)) - { - ExprState *exprstate; - ExprContext *ectx; - bool isNull; + if (contain_volatile_functions((Node *) expr)) + return false; - exprstate = context->exprstates[stateidx]; - ectx = context->planstate->ps_ExprContext; - *value = ExecEvalExprSwitchContext(exprstate, ectx, &isNull); - if (isNull) - return false; + if (IsA(expr, Const)) + { + *value = ((Const *) expr)->constvalue; + return true; + } + else + { + /* + * When being called from the executor we may be able to evaluate + * the Param's value. + */ + if (context->planstate && + bms_is_member(((Param *) expr)->paramid, context->safeparams)) + { + ExprState *exprstate; + ExprContext *ectx; + bool isNull; - return true; - } - break; + exprstate = context->exprstates[stateidx]; + ectx = context->planstate->ps_ExprContext; + *value = ExecEvalExprSwitchContext(exprstate, ectx, &isNull); + if (isNull) + return false; - default: - break; + return true; + } } return false;