staticvoid InitQueryHashTable(void); static ParamListInfo EvaluateParams(ParseState *pstate,
PreparedStatement *pstmt, List *params,
EState *estate); static Datum build_regtype_array(Oid *param_types, int num_params);
/* *Implementsthe'PREPARE'utilitystatement.
*/ void
PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
{
RawStmt *rawstmt;
CachedPlanSource *plansource;
Oid *argtypes = NULL; int nargs;
List *query_list;
/* *Disallowempty-stringstatementname(conflictswithprotocol-level *unnamedstatement).
*/ if (!stmt->name || stmt->name[0] == '\0')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PSTATEMENT_DEFINITION),
errmsg("invalid statement name: must not be empty")));
/* Look it up in the hash table */
entry = FetchPreparedStatement(stmt->name, true);
/* Shouldn't find a non-fixed-result cached plan */ if (!entry->plansource->fixed_result)
elog(ERROR, "EXECUTE does not support variable-result cached plans");
/* Evaluate parameters, if any */ if (entry->plansource->num_params > 0)
{ /* *NeedanEStatetoevaluateparameters;mustnotdeleteittillend *ofquery,incaseparametersarepass-by-reference.Notethatthe *passed-in"params"couldpossiblybereferencedintheparameter *expressions.
*/
estate = CreateExecutorState();
estate->es_param_list_info = params;
paramLI = EvaluateParams(pstate, entry, stmt->params, estate);
}
/* Create a new portal to run the query in */
portal = CreateNewPortal(); /* Don't display the portal in pg_cursors, it is for internal use only */
portal->visible = false;
/* Copy the plan's saved query string into the portal's memory */
query_string = MemoryContextStrdup(portal->portalContext,
entry->plansource->query_string);
/* Replan if needed, and increment plan refcount for portal */
cplan = GetCachedPlan(entry->plansource, paramLI, NULL, NULL);
plan_list = cplan->stmt_list;
if (list_length(plan_list) != 1)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("prepared statement is not a SELECT")));
pstmt = linitial_node(PlannedStmt, plan_list); if (pstmt->commandType != CMD_SELECT)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("prepared statement is not a SELECT")));
/* Set appropriate eflags */
eflags = GetIntoRelEFlags(intoClause);
/* And tell PortalRun whether to run to completion or not */ if (intoClause->skipData)
count = 0; else
count = FETCH_ALL;
} else
{ /* Plain old EXECUTE */
eflags = 0;
count = FETCH_ALL;
}
/* No need to pfree other memory, MemoryContext will be reset */
}
/* *EvaluateParams:evaluatealistofparameters. * *pstate:parsestate *pstmt:statementwearegettingparametersfor. *params:listofgivenparameterexpressions(rawparseroutput!) *estate:executorstatetouse. * *Returnsafilled-inParamListInfo--thiscanlaterbepassedto *CreateQueryDesc(),whichallowstheexecutortomakeuseoftheparameters *duringqueryexecution.
*/ static ParamListInfo
EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params,
EState *estate)
{
Oid *param_types = pstmt->plansource->param_types; int num_params = pstmt->plansource->num_params; int nparams = list_length(params);
ParamListInfo paramLI;
List *exprstates;
ListCell *l; int i;
if (nparams != num_params)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("wrong number of parameters for prepared statement \"%s\"",
pstmt->stmt_name),
errdetail("Expected %d parameters but got %d.",
num_params, nparams)));
/* Quick exit if no parameters */ if (num_params == 0) return NULL;
if (expr == NULL)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("parameter $%d of type %s cannot be coerced to the expected type %s",
i + 1,
format_type_be(given_type_id),
format_type_be(expected_type_id)),
errhint("You will need to rewrite or cast the expression."),
parser_errposition(pstate, exprLocation(lfirst(l)))));
/* Take care of collations in the finished expression. */
assign_expr_collations(pstate, expr);
lfirst(l) = expr;
i++;
}
/* Prepare the expressions for execution */
exprstates = ExecPrepareExprList(params, estate);
if (es->memory)
{ /* See ExplainOneQuery about this */
Assert(IsA(CurrentMemoryContext, AllocSetContext));
planner_ctx = AllocSetContextCreate(CurrentMemoryContext, "explain analyze planner context",
ALLOCSET_DEFAULT_SIZES);
saved_ctx = MemoryContextSwitchTo(planner_ctx);
}
if (es->buffers)
bufusage_start = pgBufferUsage;
INSTR_TIME_SET_CURRENT(planstart);
/* Look it up in the hash table */
entry = FetchPreparedStatement(execstmt->name, true);
/* Shouldn't find a non-fixed-result cached plan */ if (!entry->plansource->fixed_result)
elog(ERROR, "EXPLAIN EXECUTE does not support variable-result cached plans");
query_string = entry->plansource->query_string;
/* Evaluate parameters, if any */ if (entry->plansource->num_params)
{
ParseState *pstate_params;
/* *ThisutilityfunctiontakesaCarrayofOids,andreturnsaDatum *pointingtoaone-dimensionalPostgresarrayofregtypes.Anempty *arrayisreturnedasazero-elementarray,notNULL.
*/ static Datum
build_regtype_array(Oid *param_types, int num_params)
{
Datum *tmp_ary;
ArrayType *result; int i;
tmp_ary = palloc_array(Datum, num_params);
for (i = 0; i < num_params; i++)
tmp_ary[i] = ObjectIdGetDatum(param_types[i]);
result = construct_array_builtin(tmp_ary, num_params, REGTYPEOID); return PointerGetDatum(result);
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.19Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.