summaryrefslogtreecommitdiff
path: root/src/backend/commands/prepare.c
diff options
context:
space:
mode:
authorPeter Eisentraut2022-03-04 13:49:37 +0000
committerPeter Eisentraut2022-03-07 07:13:30 +0000
commit25751f54b8e02a8fff62e9dbdbc9f2efbb4e8dc1 (patch)
tree6de17d8744ac53b5b786a9427c83bf201b8df50b /src/backend/commands/prepare.c
parent5e0e99a80b2f41c8e9ed0f4071892d9e797a12be (diff)
Add pg_analyze_and_rewrite_varparams()
This new function extracts common code from PrepareQuery() and exec_parse_message(). It is then exactly analogous to the existing pg_analyze_and_rewrite_fixedparams() and pg_analyze_and_rewrite_withcb(). To unify these two code paths, this makes PrepareQuery() now subject to log_parser_stats. Also, both paths now invoke TRACE_POSTGRESQL_QUERY_REWRITE_START(). PrepareQuery() no longer checks whether a utility statement was specified. The grammar doesn't allow that anyway, and exec_parse_message() supports it, so restricting it doesn't seem necessary. This also adds QueryEnvironment support to the *varparams functions, for consistency with its cousins, even though it is not used right now. Reviewed-by: Nathan Bossart <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/[email protected]
Diffstat (limited to 'src/backend/commands/prepare.c')
-rw-r--r--src/backend/commands/prepare.c43
1 files changed, 4 insertions, 39 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index d2d8ee120c3..80738547ed8 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -63,9 +63,7 @@ PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
CachedPlanSource *plansource;
Oid *argtypes = NULL;
int nargs;
- Query *query;
List *query_list;
- int i;
/*
* Disallow empty-string statement name (conflicts with protocol-level
@@ -97,6 +95,7 @@ PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
if (nargs)
{
+ int i;
ListCell *l;
argtypes = (Oid *) palloc(nargs * sizeof(Oid));
@@ -115,44 +114,10 @@ PrepareQuery(ParseState *pstate, PrepareStmt *stmt,
* Analyze the statement using these parameter types (any parameters
* passed in from above us will not be visible to it), allowing
* information about unknown parameters to be deduced from context.
+ * Rewrite the query. The result could be 0, 1, or many queries.
*/
- query = parse_analyze_varparams(rawstmt, pstate->p_sourcetext,
- &argtypes, &nargs);
-
- /*
- * Check that all parameter types were determined.
- */
- for (i = 0; i < nargs; i++)
- {
- Oid argtype = argtypes[i];
-
- if (argtype == InvalidOid || argtype == UNKNOWNOID)
- ereport(ERROR,
- (errcode(ERRCODE_INDETERMINATE_DATATYPE),
- errmsg("could not determine data type of parameter $%d",
- i + 1)));
- }
-
- /*
- * grammar only allows PreparableStmt, so this check should be redundant
- */
- switch (query->commandType)
- {
- case CMD_SELECT:
- case CMD_INSERT:
- case CMD_UPDATE:
- case CMD_DELETE:
- /* OK */
- break;
- default:
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PSTATEMENT_DEFINITION),
- errmsg("utility statements cannot be prepared")));
- break;
- }
-
- /* Rewrite the query. The result could be 0, 1, or many queries. */
- query_list = QueryRewrite(query);
+ query_list = pg_analyze_and_rewrite_varparams(rawstmt, pstate->p_sourcetext,
+ &argtypes, &nargs, NULL);
/* Finish filling in the CachedPlanSource */
CompleteCachedPlan(plansource,