86 #define StmtPlanRequiresRevalidation(plansource) \
87 ((plansource)->raw_parse_tree != NULL && \
88 stmt_requires_parse_analysis((plansource)->raw_parse_tree))
169 const char *query_string,
176 Assert(query_string != NULL);
208 plansource->
context = source_context;
217 plansource->
gplan = NULL;
253 const char *query_string,
258 Assert(query_string != NULL);
285 plansource->
gplan = NULL;
343 List *querytree_list,
348 void *parserSetupArg,
370 else if (querytree_context != NULL)
425 memcpy(plansource->
param_types, param_types, num_params *
sizeof(
Oid));
467 elog(
ERROR,
"cannot save one-shot cached plan");
517 plansource->
magic = 0;
534 if (plansource->
gplan)
539 plansource->
gplan = NULL;
595 if (plansource->
gplan)
673 snapshot_set =
false;
713 if (resultDesc == NULL && plansource->
resultDesc == NULL)
717 else if (resultDesc == NULL || plansource->
resultDesc == NULL ||
723 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
724 errmsg(
"cached plan must not change result type")));
817 if (
plan->is_valid &&
plan->dependsOnRole &&
819 plan->is_valid =
false;
839 if (
plan->is_valid &&
842 plan->is_valid =
false;
927 snapshot_set =
false;
974 plan->stmt_list = plist;
983 is_transient =
false;
994 plan->dependsOnRole =
true;
1004 plan->context = plan_context;
1006 plan->is_saved =
false;
1007 plan->is_valid =
true;
1025 double avg_custom_cost;
1032 if (boundParams == NULL)
1085 foreach(lc,
plan->stmt_list)
1094 if (include_planner)
1156 if (owner && !plansource->
is_saved)
1157 elog(
ERROR,
"cannot apply ResourceOwner to non-saved cached plan");
1187 plan->is_saved =
true;
1247 if (customplan && plansource->
is_saved)
1250 plan->is_saved =
true;
1278 if (
plan->refcount == 0)
1284 if (!
plan->is_oneshot)
1345 if (
plan->dependsOnRole)
1370 foreach(lc,
plan->stmt_list)
1382 foreach(lc2, plannedstmt->
rtable)
1484 elog(
ERROR,
"cannot move a saved cached plan to another context");
1486 elog(
ERROR,
"cannot move a one-shot cached plan to another context");
1496 if (plansource->
gplan)
1528 elog(
ERROR,
"cannot copy a one-shot cached plan");
1560 newsource->
context = source_context;
1576 newsource->
gplan = NULL;
1688 cexpr->
context = cexpr_context;
1738 if (
stmt->canSetTag)
1753 foreach(lc1, stmt_list)
1774 foreach(lc2, plannedstmt->
rtable)
1809 foreach(lc, stmt_list)
1840 foreach(lc, parsetree->
rtable)
1874 foreach(lc, parsetree->
cteList)
1885 if (parsetree->hasSubLinks)
1989 if (plansource->
gplan)
2075 if (hashvalue == 0 ||
2080 if (plansource->
gplan)
2105 if (hashvalue == 0 ||
2138 if (hashvalue == 0 ||
2191 if (plansource->
gplan)
#define OidIsValid(objectId)
elog(ERROR, "%s: %s", p2, msg)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc ExecCleanTypeFromTL(List *targetList)
#define dlist_foreach(iter, lhead)
static void dlist_delete(dlist_node *node)
static void dlist_push_tail(dlist_head *head, dlist_node *node)
#define DLIST_STATIC_INIT(name)
#define dlist_container(type, membername, ptr)
void CacheRegisterRelcacheCallback(RelcacheCallbackFunction func, Datum arg)
void CacheRegisterSyscacheCallback(int cacheid, SyscacheCallbackFunction func, Datum arg)
Assert(fmt[strlen(fmt) - 1] !='\n')
bool list_member_oid(const List *list, Oid datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
char * pstrdup(const char *in)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
MemoryContext MemoryContextGetParent(MemoryContext context)
MemoryContext CacheMemoryContext
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define AllocSetContextCreate
#define ALLOCSET_START_SMALL_SIZES
#define ALLOCSET_SMALL_SIZES
#define MemoryContextCopyAndSetIdentifier(cxt, id)
SearchPathMatcher * CopySearchPathMatcher(SearchPathMatcher *path)
bool SearchPathMatchesCurrentEnvironment(SearchPathMatcher *path)
SearchPathMatcher * GetSearchPathMatcher(MemoryContext context)
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_RC_SUBQUERIES
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
#define CURSOR_OPT_GENERIC_PLAN
#define CURSOR_OPT_CUSTOM_PLAN
bool analyze_requires_snapshot(RawStmt *parseTree)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
void CachedPlanSetParentContext(CachedPlanSource *plansource, MemoryContext newcontext)
bool CachedPlanIsValid(CachedPlanSource *plansource)
static dlist_head cached_expression_list
void DropCachedPlan(CachedPlanSource *plansource)
static bool choose_custom_plan(CachedPlanSource *plansource, ParamListInfo boundParams)
List * CachedPlanGetTargetList(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
bool CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
static void ReleaseGenericPlan(CachedPlanSource *plansource)
static CachedPlan * BuildCachedPlan(CachedPlanSource *plansource, List *qlist, ParamListInfo boundParams, QueryEnvironment *queryEnv)
static bool CheckCachedPlan(CachedPlanSource *plansource)
void FreeCachedExpression(CachedExpression *cexpr)
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)
bool CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
CachedPlan * GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ResourceOwner owner, QueryEnvironment *queryEnv)
static bool ScanQueryWalker(Node *node, bool *acquire)
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue)
static List * RevalidateCachedQuery(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
CachedExpression * GetCachedExpression(Node *expr)
static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue)
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
static TupleDesc PlanCacheComputeResultDesc(List *stmt_list)
static dlist_head saved_plan_list
static void AcquirePlannerLocks(List *stmt_list, bool acquire)
static double cached_plan_cost(CachedPlan *plan, bool include_planner)
static void ScanQueryForLocks(Query *parsetree, bool acquire)
void ResetPlanCache(void)
CachedPlanSource * CreateOneShotCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
CachedPlanSource * CopyCachedPlan(CachedPlanSource *plansource)
static void PlanCacheRelCallback(Datum arg, Oid relid)
static Query * QueryListGetPrimaryStmt(List *stmts)
#define StmtPlanRequiresRevalidation(plansource)
static void AcquireExecutorLocks(List *stmt_list, bool acquire)
#define CACHEDPLANSOURCE_MAGIC
@ PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN
@ PLAN_CACHE_MODE_FORCE_GENERIC_PLAN
Expr * expression_planner_with_deps(Expr *expr, List **relationOids, List **invalItems)
List * pg_analyze_and_rewrite_withcb(RawStmt *parsetree, const char *query_string, ParserSetupHook parserSetup, void *parserSetupArg, QueryEnvironment *queryEnv)
List * pg_analyze_and_rewrite_fixedparams(RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
List * pg_plan_queries(List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
PortalStrategy ChoosePortalStrategy(List *stmts)
List * FetchStatementTargetList(Node *stmt)
void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan *plan)
void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan *plan)
void ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner)
void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity)
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
TransactionId TransactionXmin
bool ActiveSnapshotSet(void)
void PopActiveSnapshot(void)
struct CachedPlan * gplan
struct SearchPathMatcher * search_path
MemoryContext query_context
const char * query_string
ParserSetupHook parserSetup
struct RawStmt * raw_parse_tree
#define InvalidTransactionId
#define TransactionIdEquals(id1, id2)
#define TransactionIdIsValid(xid)
#define TransactionIdIsNormal(xid)
void FreeTupleDesc(TupleDesc tupdesc)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
bool equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
Query * UtilityContainsQuery(Node *parsetree)
TupleDesc UtilityTupleDescriptor(Node *parsetree)