117 .
name =
"plancache reference",
184 const char *query_string,
191 Assert(query_string != NULL);
226 plansource->
context = source_context;
235 plansource->
gplan = NULL;
264 const char *query_string,
299 const char *query_string,
304 Assert(query_string != NULL);
334 plansource->
gplan = NULL;
392 List *querytree_list,
397 void *parserSetupArg,
419 else if (querytree_context != NULL)
474 memcpy(plansource->
param_types, param_types, num_params *
sizeof(
Oid));
507 void *postRewriteArg)
539 elog(
ERROR,
"cannot save one-shot cached plan");
589 plansource->
magic = 0;
606 if (plansource->
gplan)
611 plansource->
gplan = NULL;
705 if (plansource->
gplan)
783 snapshot_set =
false;
819 Query *analyzed_tree;
849 if (resultDesc == NULL && plansource->
resultDesc == NULL)
853 else if (resultDesc == NULL || plansource->
resultDesc == NULL ||
859 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
860 errmsg(
"cached plan must not change result type")));
953 if (
plan->is_valid &&
plan->dependsOnRole &&
955 plan->is_valid =
false;
975 if (
plan->is_valid &&
978 plan->is_valid =
false;
1063 snapshot_set =
false;
1068 snapshot_set =
true;
1109 plan->stmt_list = plist;
1118 is_transient =
false;
1127 is_transient =
true;
1129 plan->dependsOnRole =
true;
1139 plan->context = plan_context;
1141 plan->is_saved =
false;
1142 plan->is_valid =
true;
1160 double avg_custom_cost;
1167 if (boundParams == NULL)
1220 foreach(lc,
plan->stmt_list)
1229 if (include_planner)
1291 if (owner && !plansource->
is_saved)
1292 elog(
ERROR,
"cannot apply ResourceOwner to non-saved cached plan");
1322 plan->is_saved =
true;
1382 if (customplan && plansource->
is_saved)
1385 plan->is_saved =
true;
1413 if (
plan->refcount == 0)
1419 if (!
plan->is_oneshot)
1480 if (
plan->dependsOnRole)
1505 foreach(lc,
plan->stmt_list)
1517 foreach(lc2, plannedstmt->
rtable)
1619 elog(
ERROR,
"cannot move a saved cached plan to another context");
1621 elog(
ERROR,
"cannot move a one-shot cached plan to another context");
1631 if (plansource->
gplan)
1663 elog(
ERROR,
"cannot copy a one-shot cached plan");
1698 newsource->
context = source_context;
1714 newsource->
gplan = NULL;
1826 cexpr->
context = cexpr_context;
1876 if (
stmt->canSetTag)
1891 foreach(lc1, stmt_list)
1912 foreach(lc2, plannedstmt->
rtable)
1947 foreach(lc, stmt_list)
1978 foreach(lc, parsetree->
rtable)
2012 foreach(lc, parsetree->
cteList)
2023 if (parsetree->hasSubLinks)
2125 if (plansource->
gplan)
2211 if (hashvalue == 0 ||
2216 if (plansource->
gplan)
2241 if (hashvalue == 0 ||
2274 if (hashvalue == 0 ||
2327 if (plansource->
gplan)
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc ExecCleanTypeFromTL(List *targetList)
Assert(PointerIsAligned(start, uint64))
#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)
bool list_member_oid(const List *list, Oid datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
char * pstrdup(const char *in)
void MemoryContextSetParent(MemoryContext context, MemoryContext new_parent)
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 * GetSearchPathMatcher(MemoryContext context)
bool SearchPathMatchesCurrentEnvironment(SearchPathMatcher *path)
SearchPathMatcher * CopySearchPathMatcher(SearchPathMatcher *path)
#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)
bool query_requires_rewrite_plan(Query *query)
bool stmt_requires_parse_analysis(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)
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)
static bool StmtPlanRequiresRevalidation(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)
static void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, CachedPlan *plan)
CachedPlan * GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ResourceOwner owner, QueryEnvironment *queryEnv)
CachedExpression * GetCachedExpression(Node *expr)
bool CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
CachedPlanSource * CreateOneShotCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
CachedPlanSource * CreateCachedPlanForQuery(Query *analyzed_parse_tree, const char *query_string, CommandTag commandTag)
static bool ScanQueryWalker(Node *node, bool *acquire)
void SetPostRewriteHook(CachedPlanSource *plansource, PostRewriteHook postRewrite, void *postRewriteArg)
static const ResourceOwnerDesc planref_resowner_desc
static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue)
static List * RevalidateCachedQuery(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
CachedPlanSource * CreateCachedPlan(RawStmt *raw_parse_tree, const char *query_string, CommandTag commandTag)
static void PlanCacheObjectCallback(Datum arg, int cacheid, uint32 hashvalue)
List * CachedPlanGetTargetList(CachedPlanSource *plansource, QueryEnvironment *queryEnv)
CachedPlanSource * CopyCachedPlan(CachedPlanSource *plansource)
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 void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, CachedPlan *plan)
static double cached_plan_cost(CachedPlan *plan, bool include_planner)
static void ResOwnerReleaseCachedPlan(Datum res)
static void ScanQueryForLocks(Query *parsetree, bool acquire)
void ReleaseAllPlanCacheRefsInOwner(ResourceOwner owner)
void ResetPlanCache(void)
static void PlanCacheRelCallback(Datum arg, Oid relid)
static Query * QueryListGetPrimaryStmt(List *stmts)
static bool BuildingPlanRequiresSnapshot(CachedPlanSource *plansource)
static void AcquireExecutorLocks(List *stmt_list, bool acquire)
void(* PostRewriteHook)(List *querytree_list, void *arg)
#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_plan_queries(List *querytrees, const char *query_string, int cursorOptions, ParamListInfo boundParams)
List * pg_analyze_and_rewrite_fixedparams(RawStmt *parsetree, const char *query_string, const Oid *paramTypes, int numParams, QueryEnvironment *queryEnv)
List * pg_rewrite_query(Query *query)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
PortalStrategy ChoosePortalStrategy(List *stmts)
List * FetchStatementTargetList(Node *stmt)
void ResourceOwnerForget(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerReleaseAllOfKind(ResourceOwner owner, const ResourceOwnerDesc *kind)
void ResourceOwnerRemember(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerEnlarge(ResourceOwner owner)
#define RELEASE_PRIO_PLANCACHE_REFS
@ RESOURCE_RELEASE_AFTER_LOCKS
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
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
PostRewriteHook postRewrite
struct Query * analyzed_parse_tree
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 equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)
Query * UtilityContainsQuery(Node *parsetree)
TupleDesc UtilityTupleDescriptor(Node *parsetree)