96 bool release_generic);
118 .
name =
"plancache reference",
185 const char *query_string,
192 Assert(query_string != NULL);
227 plansource->
context = source_context;
236 plansource->
gplan = NULL;
265 const char *query_string,
300 const char *query_string,
305 Assert(query_string != NULL);
335 plansource->
gplan = NULL;
393 List *querytree_list,
398 void *parserSetupArg,
420 else if (querytree_context != NULL)
475 memcpy(plansource->
param_types, param_types, num_params *
sizeof(
Oid));
508 void *postRewriteArg)
540 elog(
ERROR,
"cannot save one-shot cached plan");
590 plansource->
magic = 0;
607 if (plansource->
gplan)
612 plansource->
gplan = NULL;
676 bool release_generic)
713 if (plansource->
gplan)
792 snapshot_set =
false;
828 Query *analyzed_tree;
858 if (resultDesc == NULL && plansource->
resultDesc == NULL)
862 else if (resultDesc == NULL || plansource->
resultDesc == NULL ||
868 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
869 errmsg(
"cached plan must not change result type")));
964 if (
plan->is_valid &&
plan->dependsOnRole &&
966 plan->is_valid =
false;
986 if (
plan->is_valid &&
989 plan->is_valid =
false;
1077 snapshot_set =
false;
1082 snapshot_set =
true;
1118 "CachedPlan PlannedStmts",
1137 plan->stmt_list = plist;
1146 is_transient =
false;
1155 is_transient =
true;
1157 plan->dependsOnRole =
true;
1167 plan->context = plan_context;
1168 plan->stmt_context = stmt_context;
1170 plan->is_saved =
false;
1171 plan->is_reused =
false;
1172 plan->is_valid =
true;
1219 elog(
ERROR,
"UpdateCachedPlan() called in the wrong context: plansource->gplan is NULL");
1220 else if (
plan->is_valid)
1221 elog(
ERROR,
"UpdateCachedPlan() called in the wrong context: plansource->gplan->is_valid is true");
1222 else if (
plan->is_oneshot)
1223 elog(
ERROR,
"UpdateCachedPlan() called in the wrong context: plansource->gplan->is_oneshot is true");
1281 plan->is_valid =
true;
1297 double avg_custom_cost;
1304 if (boundParams == NULL)
1357 foreach(lc,
plan->stmt_list)
1366 if (include_planner)
1433 if (owner && !plansource->
is_saved)
1434 elog(
ERROR,
"cannot apply ResourceOwner to non-saved cached plan");
1450 plan->is_reused =
true;
1466 plan->is_saved =
true;
1526 if (customplan && plansource->
is_saved)
1529 plan->is_saved =
true;
1557 if (
plan->refcount == 0)
1563 if (!
plan->is_oneshot)
1624 if (
plan->dependsOnRole)
1649 foreach(lc,
plan->stmt_list)
1661 foreach(lc2, plannedstmt->
rtable)
1763 elog(
ERROR,
"cannot move a saved cached plan to another context");
1765 elog(
ERROR,
"cannot move a one-shot cached plan to another context");
1775 if (plansource->
gplan)
1807 elog(
ERROR,
"cannot copy a one-shot cached plan");
1842 newsource->
context = source_context;
1858 newsource->
gplan = NULL;
1970 cexpr->
context = cexpr_context;
2020 if (
stmt->canSetTag)
2035 foreach(lc1, stmt_list)
2094 foreach(lc, stmt_list)
2125 foreach(lc, parsetree->
rtable)
2159 foreach(lc, parsetree->
cteList)
2170 if (parsetree->hasSubLinks)
2272 if (plansource->
gplan)
2358 if (hashvalue == 0 ||
2363 if (plansource->
gplan)
2388 if (hashvalue == 0 ||
2421 if (hashvalue == 0 ||
2474 if (plansource->
gplan)
int bms_next_member(const Bitmapset *a, int prevbit)
#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)
List * list_copy(const List *oldlist)
bool list_member_oid(const List *list, Oid datum)
void UnlockRelationOid(Oid relid, LOCKMODE lockmode)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
void MemoryContextReset(MemoryContext context)
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)
#define forboth(cell1, list1, cell2, list2)
#define list_nth_node(type, list, n)
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 List * RevalidateCachedQuery(CachedPlanSource *plansource, QueryEnvironment *queryEnv, bool release_generic)
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)
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
PlannedStmt * UpdateCachedPlan(CachedPlanSource *plansource, int query_index, QueryEnvironment *queryEnv)
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
Bitmapset * unprunableRelids
#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)