diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/optimizer/planmain.h | 2 | ||||
-rw-r--r-- | src/include/optimizer/planner.h | 3 | ||||
-rw-r--r-- | src/include/utils/plancache.h | 51 |
3 files changed, 45 insertions, 11 deletions
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index a081ca689a3..ec1ea102331 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -118,9 +118,11 @@ extern bool innerrel_is_unique(PlannerInfo *root, */ extern Plan *set_plan_references(PlannerInfo *root, Plan *plan); extern void record_plan_function_dependency(PlannerInfo *root, Oid funcid); +extern void record_plan_type_dependency(PlannerInfo *root, Oid typeid); extern void extract_query_dependencies(Node *query, List **relationOids, List **invalItems, bool *hasRowSecurity); +extern bool extract_query_dependencies_walker(Node *node, PlannerInfo *root); #endif /* PLANMAIN_H */ diff --git a/src/include/optimizer/planner.h b/src/include/optimizer/planner.h index 3e733b34ed9..902ab403ed9 100644 --- a/src/include/optimizer/planner.h +++ b/src/include/optimizer/planner.h @@ -55,6 +55,9 @@ extern Path *get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction); extern Expr *expression_planner(Expr *expr); +extern Expr *expression_planner_with_deps(Expr *expr, + List **relationOids, + List **invalItems); extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr); diff --git a/src/include/utils/plancache.h b/src/include/utils/plancache.h index 5fc7903a068..7fd7ea6c168 100644 --- a/src/include/utils/plancache.h +++ b/src/include/utils/plancache.h @@ -16,14 +16,27 @@ #define PLANCACHE_H #include "access/tupdesc.h" +#include "lib/ilist.h" #include "nodes/params.h" #include "utils/queryenvironment.h" /* Forward declaration, to avoid including parsenodes.h here */ struct RawStmt; +/* possible values for plan_cache_mode */ +typedef enum +{ + PLAN_CACHE_MODE_AUTO, + PLAN_CACHE_MODE_FORCE_GENERIC_PLAN, + PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN +} PlanCacheMode; + +/* GUC parameter */ +extern int plan_cache_mode; + #define CACHEDPLANSOURCE_MAGIC 195726186 #define CACHEDPLAN_MAGIC 953717834 +#define CACHEDEXPR_MAGIC 838275847 /* * CachedPlanSource (which might better have been called CachedQuery) @@ -110,7 +123,7 @@ typedef struct CachedPlanSource bool is_valid; /* is the query_list currently valid? */ int generation; /* increments each time we create a plan */ /* If CachedPlanSource has been saved, it is a member of a global list */ - struct CachedPlanSource *next_saved; /* list link, if so */ + dlist_node node; /* list link, if is_saved */ /* State kept to help decide whether to use custom or generic plans: */ double generic_cost; /* cost of generic plan, or -1 if not known */ double total_custom_cost; /* total cost of custom plans so far */ @@ -143,6 +156,30 @@ typedef struct CachedPlan MemoryContext context; /* context containing this CachedPlan */ } CachedPlan; +/* + * CachedExpression is a low-overhead mechanism for caching the planned form + * of standalone scalar expressions. While such expressions are not usually + * subject to cache invalidation events, that can happen, for example because + * of replacement of a SQL function that was inlined into the expression. + * The plancache takes care of storing the expression tree and marking it + * invalid if a cache invalidation occurs, but the caller must notice the + * !is_valid status and discard the obsolete expression without reusing it. + * We do not store the original parse tree, only the planned expression; + * this is an optimization based on the assumption that we usually will not + * need to replan for the life of the session. + */ +typedef struct CachedExpression +{ + int magic; /* should equal CACHEDEXPR_MAGIC */ + Node *expr; /* planned form of expression */ + bool is_valid; /* is the expression still valid? */ + /* remaining fields should be treated as private to plancache.c: */ + List *relationOids; /* OIDs of relations the expr depends on */ + List *invalItems; /* other dependencies, as PlanInvalItems */ + MemoryContext context; /* context containing this CachedExpression */ + dlist_node node; /* link in global list of CachedExpressions */ +} CachedExpression; + extern void InitPlanCache(void); extern void ResetPlanCache(void); @@ -182,15 +219,7 @@ extern CachedPlan *GetCachedPlan(CachedPlanSource *plansource, QueryEnvironment *queryEnv); extern void ReleaseCachedPlan(CachedPlan *plan, bool useResOwner); -/* possible values for plan_cache_mode */ -typedef enum -{ - PLAN_CACHE_MODE_AUTO, - PLAN_CACHE_MODE_FORCE_GENERIC_PLAN, - PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN -} PlanCacheMode; - -/* GUC parameter */ -extern int plan_cache_mode; +extern CachedExpression *GetCachedExpression(Node *expr); +extern void FreeCachedExpression(CachedExpression *cexpr); #endif /* PLANCACHE_H */ |