* Create a ParamListInfo to pass to SPI * * We use a single ParamListInfo struct for all SPI calls made to evaluate * PLpgSQL_exprs in this estate. It contains no per-param data, just hook * functions, so it's effectively read-only for SPI. * * An exception from pure read-only-ness is that the parserSetupArg points * to the specific PLpgSQL_expr being evaluated. This is not an issue for
| 6183 | * that seems like a waste of memory.) |
| 6184 | */ |
| 6185 | static ParamListInfo |
| 6186 | setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr) |
| 6187 | { |
| 6188 | ParamListInfo paramLI; |
| 6189 | |
| 6190 | /* |
| 6191 | * We must have created the SPIPlan already (hence, query text has been |
| 6192 | * parsed/analyzed at least once); else we cannot rely on expr->paramnos. |
| 6193 | */ |
| 6194 | Assert(expr->plan != NULL); |
| 6195 | |
| 6196 | /* |
| 6197 | * We only need a ParamListInfo if the expression has parameters. In |
| 6198 | * principle we should test with bms_is_empty(), but we use a not-null |
| 6199 | * test because it's faster. In current usage bits are never removed from |
| 6200 | * expr->paramnos, only added, so this test is correct anyway. |
| 6201 | */ |
| 6202 | if (expr->paramnos) |
| 6203 | { |
| 6204 | /* Use the common ParamListInfo */ |
| 6205 | paramLI = estate->paramLI; |
| 6206 | |
| 6207 | /* |
| 6208 | * Set up link to active expr where the hook functions can find it. |
| 6209 | * Callers must save and restore parserSetupArg if there is any chance |
| 6210 | * that they are interrupting an active use of parameters. |
| 6211 | */ |
| 6212 | paramLI->parserSetupArg = (void *) expr; |
| 6213 | |
| 6214 | /* |
| 6215 | * Also make sure this is set before parser hooks need it. There is |
| 6216 | * no need to save and restore, since the value is always correct once |
| 6217 | * set. (Should be set already, but let's be sure.) |
| 6218 | */ |
| 6219 | expr->func = estate->func; |
| 6220 | } |
| 6221 | else |
| 6222 | { |
| 6223 | /* |
| 6224 | * Expression requires no parameters. Be sure we represent this case |
| 6225 | * as a NULL ParamListInfo, so that plancache.c knows there is no |
| 6226 | * point in a custom plan. |
| 6227 | */ |
| 6228 | paramLI = NULL; |
| 6229 | } |
| 6230 | return paramLI; |
| 6231 | } |
| 6232 | |
| 6233 | /* |
| 6234 | * plpgsql_param_fetch paramFetch callback for dynamic parameter fetch |
no outgoing calls
no test coverage detected