85#define StmtPlanRequiresRevalidation(plansource) \
86 ((plansource)->raw_parse_tree != NULL && \
87 stmt_requires_parse_analysis((plansource)->raw_parse_tree))
126 .
name =
"plancache reference",
193 const char *query_string,
200 Assert(query_string != NULL);
232 plansource->
context = source_context;
241 plansource->
gplan = NULL;
277 const char *query_string,
282 Assert(query_string != NULL);
309 plansource->
gplan = NULL;
367 List *querytree_list,
372 void *parserSetupArg,
394 else if (querytree_context != NULL)
449 memcpy(plansource->
param_types, param_types, num_params *
sizeof(
Oid));
491 elog(
ERROR,
"cannot save one-shot cached plan");
541 plansource->
magic = 0;
558 if (plansource->
gplan)
563 plansource->
gplan = NULL;
619 if (plansource->
gplan)
697 snapshot_set =
false;
736 if (resultDesc == NULL && plansource->
resultDesc == NULL)
740 else if (resultDesc == NULL || plansource->
resultDesc == NULL ||
746 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
747 errmsg(
"cached plan must not change result type")));
840 if (
plan->is_valid &&
plan->dependsOnRole &&
842 plan->is_valid =
false;
862 if (
plan->is_valid &&
865 plan->is_valid =
false;
950 snapshot_set =
false;
997 plan->stmt_list = plist;
1006 is_transient =
false;
1015 is_transient =
true;
1017 plan->dependsOnRole =
true;
1027 plan->context = plan_context;
1029 plan->is_saved =
false;
1030 plan->is_valid =
true;
1048 double avg_custom_cost;
1055 if (boundParams == NULL)
1108 foreach(lc,
plan->stmt_list)
1117 if (include_planner)
1179 if (owner && !plansource->
is_saved)
1180 elog(
ERROR,
"cannot apply ResourceOwner to non-saved cached plan");
1210 plan->is_saved =
true;
1270 if (customplan && plansource->
is_saved)
1273 plan->is_saved =
true;
1301 if (
plan->refcount == 0)
1307 if (!
plan->is_oneshot)
1368 if (
plan->dependsOnRole)
1393 foreach(lc,
plan->stmt_list)
1405 foreach(lc2, plannedstmt->
rtable)
1507 elog(
ERROR,
"cannot move a saved cached plan to another context");
1509 elog(
ERROR,
"cannot move a one-shot cached plan to another context");
1519 if (plansource->
gplan)
1551 elog(
ERROR,
"cannot copy a one-shot cached plan");
1583 newsource->
context = source_context;
1599 newsource->
gplan = NULL;
1711 cexpr->
context = cexpr_context;
1761 if (
stmt->canSetTag)
1776 foreach(lc1, stmt_list)
1797 foreach(lc2, plannedstmt->
rtable)
1832 foreach(lc, stmt_list)
1863 foreach(lc, parsetree->
rtable)
1897 foreach(lc, parsetree->
cteList)
1908 if (parsetree->hasSubLinks)
2010 if (plansource->
gplan)
2096 if (hashvalue == 0 ||
2101 if (plansource->
gplan)
2126 if (hashvalue == 0 ||
2159 if (hashvalue == 0 ||
2212 if (plansource->
gplan)
#define Assert(condition)
#define OidIsValid(objectId)
static void PGresult * res
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)
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)
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)
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)
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)
static bool ScanQueryWalker(Node *node, bool *acquire)
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)
#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_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)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
PortalStrategy ChoosePortalStrategy(List *stmts)
List * FetchStatementTargetList(Node *stmt)
MemoryContextSwitchTo(old_ctx)
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 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 equalRowTypes(TupleDesc tupdesc1, TupleDesc tupdesc2)
Query * UtilityContainsQuery(Node *parsetree)
TupleDesc UtilityTupleDescriptor(Node *parsetree)