57 int stmt_location,
int stmt_len)
69 if (!
stmt->name ||
stmt->name[0] ==
'\0')
71 (
errcode(ERRCODE_INVALID_PSTATEMENT_DEFINITION),
72 errmsg(
"invalid statement name: must not be empty")));
101 foreach(l,
stmt->argtypes)
106 argtypes[
i++] = toid;
117 &argtypes, &nargs, NULL);
167 elog(
ERROR,
"EXECUTE does not support variable-result cached plans");
226 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
227 errmsg(
"prepared statement is not a SELECT")));
231 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
232 errmsg(
"prepared statement is not a SELECT")));
289 if (nparams != num_params)
291 (
errcode(ERRCODE_SYNTAX_ERROR),
292 errmsg(
"wrong number of parameters for prepared statement \"%s\"",
294 errdetail(
"Expected %d parameters but got %d.",
295 num_params, nparams)));
311 Oid expected_type_id = param_types[
i];
319 expected_type_id, -1,
326 (
errcode(ERRCODE_DATATYPE_MISMATCH),
327 errmsg(
"parameter $%d of type %s cannot be coerced to the expected type %s",
331 errhint(
"You will need to rewrite or cast the expression."),
347 foreach(l, exprstates)
352 prm->
ptype = param_types[
i];
410 (
errcode(ERRCODE_DUPLICATE_PSTATEMENT),
411 errmsg(
"prepared statement \"%s\" already exists",
447 if (!entry && throwError)
449 (
errcode(ERRCODE_UNDEFINED_PSTATEMENT),
450 errmsg(
"prepared statement \"%s\" does not exist",
470 if (
stmt->plansource->resultDesc)
573 const char *query_string;
592 "explain analyze planner context",
606 elog(
ERROR,
"EXPLAIN EXECUTE does not support variable-result cached plans");
653 foreach(p, plan_list)
659 &planduration, (es->
buffers ? &bufusage : NULL),
660 es->
memory ? &mem_counters : NULL);
668 if (
lnext(plan_list, p) != NULL)
719 for (
int i = 0;
i < result_desc->
natts;
i++)
754 for (
i = 0;
i < num_params;
i++)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static HTAB * prepared_queries
void DropPreparedStatement(const char *stmt_name, bool showError)
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
static void InitQueryHashTable(void)
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
Datum pg_prepared_statement(PG_FUNCTION_ARGS)
static ParamListInfo EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params, EState *estate)
void StorePreparedStatement(const char *stmt_name, CachedPlanSource *plansource, bool from_sql)
static Datum build_regtype_array(Oid *param_types, int num_params)
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
void DropAllPreparedStatements(void)
List * FetchPreparedStatementTargetList(PreparedStatement *stmt)
void DeallocateQuery(DeallocateStmt *stmt)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define Assert(condition)
int GetIntoRelEFlags(IntoClause *intoClause)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
List * ExecPrepareExprList(List *nodes, EState *estate)
EState * CreateExecutorState(void)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration, const BufferUsage *bufusage, const MemoryContextCounters *mem_counters)
void ExplainSeparatePlans(ExplainState *es)
void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
#define palloc_array(type, count)
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_SUBTRACT(x, y)
BufferUsage pgBufferUsage
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
void MemoryContextMemConsumed(MemoryContext context, MemoryContextCounters *consumed)
MemoryContext CurrentMemoryContext
char * MemoryContextStrdup(MemoryContext context, const char *string)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
ParamListInfo makeParamList(int numParams)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_EXECUTE_PARAMETER
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
#define CURSOR_OPT_PARALLEL_OK
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
static ListCell * lnext(const List *l, const ListCell *c)
void DropCachedPlan(CachedPlanSource *plansource)
List * CachedPlanGetTargetList(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
void SaveCachedPlan(CachedPlanSource *plansource)
void CompleteCachedPlan(CachedPlanSource *plansource, List *querytree_list, MemoryContext querytree_context, Oid *param_types, int num_params, ParserSetupHook parserSetup, void *parserSetupArg, int cursor_options, bool fixed_result)
CachedPlanSource * CreateCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
CachedPlan * GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ResourceOwner owner, QueryEnvironment *queryEnv)
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
Portal CreateNewPortal(void)
void PortalDrop(Portal portal, bool isTopCommit)
void PortalDefineQuery(Portal portal, const char *prepStmtName, const char *sourceText, CommandTag commandTag, List *stmts, CachedPlan *cplan)
List * pg_analyze_and_rewrite_varparams(RawStmt *parsetree, const char *query_string, Oid **paramTypes, int *numParams, QueryEnvironment *queryEnv)
#define Int64GetDatumFast(X)
static Datum PointerGetDatum(const void *X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot)
bool PortalRun(Portal portal, long count, bool isTopLevel, bool run_once, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
MemoryContextSwitchTo(old_ctx)
ResourceOwner CurrentResourceOwner
Snapshot GetActiveSnapshot(void)
const char * query_string
ParamListInfo es_param_list_info
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
const char * p_sourcetext
MemoryContext portalContext
char stmt_name[NAMEDATALEN]
CachedPlanSource * plansource
Tuplestorestate * setResult
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define TupleDescAttr(tupdesc, i)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
CommandTag CreateCommandTag(Node *parsetree)
static Datum TimestampTzGetDatum(TimestampTz X)
TimestampTz GetCurrentStatementStartTimestamp(void)