59 int stmt_location,
int stmt_len)
73 if (!stmt->
name || stmt->
name[0] ==
'\0')
75 (
errcode(ERRCODE_INVALID_PSTATEMENT_DEFINITION),
76 errmsg(
"invalid statement name: must not be empty")));
112 argtypes[i++] = toid;
127 for (i = 0; i < nargs; i++)
129 Oid argtype = argtypes[
i];
131 if (argtype ==
InvalidOid || argtype == UNKNOWNOID)
133 (
errcode(ERRCODE_INDETERMINATE_DATATYPE),
134 errmsg(
"could not determine data type of parameter $%d",
151 (
errcode(ERRCODE_INVALID_PSTATEMENT_DEFINITION),
152 errmsg(
"utility statements cannot be prepared")));
207 elog(
ERROR,
"EXECUTE does not support variable-result cached plans");
255 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
256 errmsg(
"prepared statement is not a SELECT")));
260 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
261 errmsg(
"prepared statement is not a SELECT")));
291 (void)
PortalRun(portal, count,
false,
true, dest, dest, qc);
325 if (nparams != num_params)
327 (
errcode(ERRCODE_SYNTAX_ERROR),
328 errmsg(
"wrong number of parameters for prepared statement \"%s\"",
330 errdetail(
"Expected %d parameters but got %d.",
331 num_params, nparams)));
347 Oid expected_type_id = param_types[
i];
355 expected_type_id, -1,
362 (
errcode(ERRCODE_DATATYPE_MISMATCH),
363 errmsg(
"parameter $%d of type %s cannot be coerced to the expected type %s",
367 errhint(
"You will need to rewrite or cast the expression."),
383 foreach(l, exprstates)
388 prm->
ptype = param_types[
i];
434 if (!prepared_queries)
446 (
errcode(ERRCODE_DUPLICATE_PSTATEMENT),
447 errmsg(
"prepared statement \"%s\" already exists",
475 if (prepared_queries)
483 if (!entry && throwError)
485 (
errcode(ERRCODE_UNDEFINED_PSTATEMENT),
486 errmsg(
"prepared statement \"%s\" does not exist",
579 if (!prepared_queries)
609 const char *query_string;
629 elog(
ERROR,
"EXPLAIN EXECUTE does not support variable-result cached plans");
669 foreach(p, plan_list)
675 &planduration, (es->
buffers ? &bufusage : NULL));
683 if (
lnext(plan_list, p) != NULL)
710 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
711 errmsg(
"set-valued function called in context that cannot accept a set")));
714 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
715 errmsg(
"materialize mode required, but it is not allowed in this context")));
731 TIMESTAMPTZOID, -1, 0);
733 REGTYPEARRAYOID, -1, 0);
753 if (prepared_queries)
764 MemSet(nulls, 0,
sizeof(nulls));
803 for (i = 0; i < num_params; i++)
808 4,
true, TYPALIGN_INT);
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define IsA(nodeptr, _type_)
List * QueryRewrite(Query *parsetree)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
int errhint(const char *fmt,...)
CachedPlan * GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, bool useResOwner, QueryEnvironment *queryEnv)
Portal CreateNewPortal(void)
CachedPlanSource * CreateCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot)
void ExplainSeparatePlans(ExplainState *es)
int exprLocation(const Node *expr)
static ListCell * lnext(const List *l, const ListCell *c)
TupleDesc CreateTemplateTupleDesc(int natts)
static void InitQueryHashTable(void)
CachedPlanSource * plansource
#define PointerGetDatum(X)
struct timeval instr_time
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
#define tuplestore_donestoring(state)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Snapshot GetActiveSnapshot(void)
static ParamListInfo EvaluateParams(ParseState *pstate, PreparedStatement *pstmt, List *params, EState *estate)
int errcode(int sqlerrcode)
Query * parse_analyze_varparams(RawStmt *parseTree, const char *sourceText, Oid **paramTypes, int *numParams)
#define MemSet(start, val, len)
void PrepareQuery(ParseState *pstate, PrepareStmt *stmt, int stmt_location, int stmt_len)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void PortalDefineQuery(Portal portal, const char *prepStmtName, const char *sourceText, CommandTag commandTag, List *stmts, CachedPlan *cplan)
#define linitial_node(type, l)
ParamListInfo makeParamList(int numParams)
MemoryContext portalContext
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
ParseState * make_parsestate(ParseState *parentParseState)
void assign_expr_collations(ParseState *pstate, Node *expr)
static HTAB * prepared_queries
bool PortalRun(Portal portal, long count, bool isTopLevel, bool run_once, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
void FreeExecutorState(EState *estate)
#define GetPerTupleExprContext(estate)
void DeallocateQuery(DeallocateStmt *stmt)
int GetIntoRelEFlags(IntoClause *intoClause)
char stmt_name[NAMEDATALEN]
#define ObjectIdGetDatum(X)
void ExplainExecuteQuery(ExecuteStmt *execstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
#define INSTR_TIME_SUBTRACT(x, y)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
#define TimestampTzGetDatum(X)
#define lfirst_node(type, lc)
List * CachedPlanGetTargetList(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
int errdetail(const char *fmt,...)
void ExecuteQuery(ParseState *pstate, ExecuteStmt *stmt, IntoClause *intoClause, ParamListInfo params, DestReceiver *dest, QueryCompletion *qc)
void ReleaseCachedPlan(CachedPlan *plan, bool useResOwner)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
const char * p_sourcetext
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
EState * CreateExecutorState(void)
List * ExecPrepareExprList(List *nodes, EState *estate)
static Datum build_regtype_array(Oid *param_types, int num_params)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt)
#define Int64GetDatumFast(X)
void StorePreparedStatement(const char *stmt_name, CachedPlanSource *plansource, bool from_sql)
List * FetchPreparedStatementTargetList(PreparedStatement *stmt)
#define ereport(elevel,...)
void SaveCachedPlan(CachedPlanSource *plansource)
void ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv, const instr_time *planduration, const BufferUsage *bufusage)
SetFunctionReturnMode returnMode
#define Assert(condition)
CommandTag CreateCommandTag(Node *parsetree)
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)
const char * query_string
Oid exprType(const Node *expr)
static int list_length(const List *l)
int parser_errposition(ParseState *pstate, int location)
void * hash_seq_search(HASH_SEQ_STATUS *status)
MemoryContext ecxt_per_query_memory
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
#define INSTR_TIME_SET_CURRENT(t)
Tuplestorestate * setResult
static Datum values[MAXATTR]
#define CURSOR_OPT_PARALLEL_OK
int errmsg(const char *fmt,...)
void PortalDrop(Portal portal, bool isTopCommit)
char * MemoryContextStrdup(MemoryContext context, const char *string)
#define CStringGetTextDatum(s)
ParamListInfo es_param_list_info
void DropCachedPlan(CachedPlanSource *plansource)
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
Datum pg_prepared_statement(PG_FUNCTION_ARGS)
void ExplainOneUtility(Node *utilityStmt, IntoClause *into, ExplainState *es, const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
BufferUsage pgBufferUsage
void DropAllPreparedStatements(void)
TimestampTz GetCurrentStatementStartTimestamp(void)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
void DropPreparedStatement(const char *stmt_name, bool showError)