@@ -3012,11 +3012,6 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
3012
3012
int rc ;
3013
3013
PLpgSQL_expr * expr = stmt -> sqlstmt ;
3014
3014
3015
- /*
3016
- * Set up ParamListInfo (hook function and possibly data values)
3017
- */
3018
- paramLI = setup_param_list (estate , expr );
3019
-
3020
3015
/*
3021
3016
* On the first call for this statement generate the plan, and detect
3022
3017
* whether the statement is INSERT/UPDATE/DELETE
@@ -3049,6 +3044,11 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
3049
3044
}
3050
3045
}
3051
3046
3047
+ /*
3048
+ * Set up ParamListInfo (hook function and possibly data values)
3049
+ */
3050
+ paramLI = setup_param_list (estate , expr );
3051
+
3052
3052
/*
3053
3053
* If we have INTO, then we only need one row back ... but if we have INTO
3054
3054
* STRICT, ask for two rows, so that we can verify the statement returns
@@ -5000,12 +5000,18 @@ setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
5000
5000
{
5001
5001
ParamListInfo paramLI ;
5002
5002
5003
+ /*
5004
+ * We must have created the SPIPlan already (hence, query text has been
5005
+ * parsed/analyzed at least once); else we cannot rely on expr->paramnos.
5006
+ */
5007
+ Assert (expr -> plan != NULL );
5008
+
5003
5009
/*
5004
5010
* Could we re-use these arrays instead of palloc'ing a new one each time?
5005
5011
* However, we'd have to re-fill the array each time anyway, since new
5006
5012
* values might have been assigned to the variables.
5007
5013
*/
5008
- if (estate -> ndatums > 0 )
5014
+ if (! bms_is_empty ( expr -> paramnos ) )
5009
5015
{
5010
5016
Bitmapset * tmpset ;
5011
5017
int dno ;
@@ -5048,12 +5054,19 @@ setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
5048
5054
/*
5049
5055
* Also make sure this is set before parser hooks need it. There is
5050
5056
* no need to save and restore, since the value is always correct once
5051
- * set.
5057
+ * set. (Should be set already, but let's be sure.)
5052
5058
*/
5053
5059
expr -> func = estate -> func ;
5054
5060
}
5055
5061
else
5062
+ {
5063
+ /*
5064
+ * Expression requires no parameters. Be sure we represent this case
5065
+ * as a NULL ParamListInfo, so that plancache.c knows there is no
5066
+ * point in a custom plan.
5067
+ */
5056
5068
paramLI = NULL ;
5069
+ }
5057
5070
return paramLI ;
5058
5071
}
5059
5072
0 commit comments