#ifndef PLANCACHE_H
#define PLANCACHE_H
#include "access/tupdesc.h"
#include "lib/ilist.h"
#include "nodes/params.h"
#include "tcop/cmdtag.h"
#include "utils/queryenvironment.h"
#include "utils/resowner.h"
struct RawStmt;
typedef enum
{
PLAN_CACHE_MODE_AUTO,
PLAN_CACHE_MODE_FORCE_GENERIC_PLAN,
PLAN_CACHE_MODE_FORCE_CUSTOM_PLAN,
} PlanCacheMode;
extern PGDLLIMPORT int plan_cache_mode;
#define CACHEDPLANSOURCE_MAGIC 195726186
#define CACHEDPLAN_MAGIC 953717834
#define CACHEDEXPR_MAGIC 838275847
typedef struct CachedPlanSource
{
int magic;
struct RawStmt *raw_parse_tree;
const char *query_string;
CommandTag commandTag;
Oid *param_types;
int num_params;
ParserSetupHook parserSetup;
void *parserSetupArg;
int cursor_options;
bool fixed_result;
TupleDesc resultDesc;
MemoryContext context;
List *query_list;
List *relationOids;
List *invalItems;
struct SearchPathMatcher *search_path;
MemoryContext query_context;
Oid rewriteRoleId;
bool rewriteRowSecurity;
bool dependsOnRLS;
struct CachedPlan *gplan;
bool is_oneshot;
bool is_complete;
bool is_saved;
bool is_valid;
int generation;
dlist_node node;
double generic_cost;
double total_custom_cost;
int64 num_custom_plans;
int64 num_generic_plans;
} CachedPlanSource;
typedef struct CachedPlan
{
int magic;
List *stmt_list;
bool is_oneshot;
bool is_saved;
bool is_valid;
Oid planRoleId;
bool dependsOnRole;
TransactionId saved_xmin;
int generation;
int refcount;
MemoryContext context;
} CachedPlan;
typedef struct CachedExpression
{
int magic;
Node *expr;
bool is_valid;
List *relationOids;
List *invalItems;
MemoryContext context;
dlist_node node;
} CachedExpression;
extern void InitPlanCache(void);
extern void ResetPlanCache(void);
extern void ReleaseAllPlanCacheRefsInOwner(ResourceOwner owner);
extern CachedPlanSource *CreateCachedPlan(struct RawStmt *raw_parse_tree,
const char *query_string,
CommandTag commandTag);
extern CachedPlanSource *CreateOneShotCachedPlan(struct RawStmt *raw_parse_tree,
const char *query_string,
CommandTag commandTag);
extern 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);
extern void SaveCachedPlan(CachedPlanSource *plansource);
extern void DropCachedPlan(CachedPlanSource *plansource);
extern void CachedPlanSetParentContext(CachedPlanSource *plansource,
MemoryContext newcontext);
extern CachedPlanSource *CopyCachedPlan(CachedPlanSource *plansource);
extern bool CachedPlanIsValid(CachedPlanSource *plansource);
extern List *CachedPlanGetTargetList(CachedPlanSource *plansource,
QueryEnvironment *queryEnv);
extern CachedPlan *GetCachedPlan(CachedPlanSource *plansource,
ParamListInfo boundParams,
ResourceOwner owner,
QueryEnvironment *queryEnv);
extern void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner);
extern bool CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource,
CachedPlan *plan,
ResourceOwner owner);
extern bool CachedPlanIsSimplyValid(CachedPlanSource *plansource,
CachedPlan *plan,
ResourceOwner owner);
extern CachedExpression *GetCachedExpression(Node *expr);
extern void FreeCachedExpression(CachedExpression *cexpr);
#endif