diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/access/xact.h | 8 | ||||
-rw-r--r-- | src/include/commands/cluster.h | 4 | ||||
-rw-r--r-- | src/include/commands/copy.h | 4 | ||||
-rw-r--r-- | src/include/commands/defrem.h | 3 | ||||
-rw-r--r-- | src/include/commands/explain.h | 11 | ||||
-rw-r--r-- | src/include/commands/portalcmds.h | 5 | ||||
-rw-r--r-- | src/include/commands/prepare.h | 41 | ||||
-rw-r--r-- | src/include/commands/schemacmds.h | 5 | ||||
-rw-r--r-- | src/include/commands/vacuum.h | 4 | ||||
-rw-r--r-- | src/include/commands/view.h | 4 | ||||
-rw-r--r-- | src/include/nodes/params.h | 5 | ||||
-rw-r--r-- | src/include/nodes/parsenodes.h | 18 | ||||
-rw-r--r-- | src/include/parser/analyze.h | 6 | ||||
-rw-r--r-- | src/include/rewrite/rewriteDefine.h | 12 | ||||
-rw-r--r-- | src/include/tcop/pquery.h | 4 | ||||
-rw-r--r-- | src/include/tcop/utility.h | 7 | ||||
-rw-r--r-- | src/include/utils/memutils.h | 5 | ||||
-rw-r--r-- | src/include/utils/plancache.h | 105 | ||||
-rw-r--r-- | src/include/utils/portal.h | 18 | ||||
-rw-r--r-- | src/include/utils/resowner.h | 10 |
20 files changed, 196 insertions, 83 deletions
diff --git a/src/include/access/xact.h b/src/include/access/xact.h index e74b87b0ed3..760b4324568 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/access/xact.h,v 1.84 2007/01/05 22:19:51 momjian Exp $ + * $PostgreSQL: pgsql/src/include/access/xact.h,v 1.85 2007/03/13 00:33:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -164,9 +164,9 @@ extern bool IsTransactionBlock(void); extern bool IsTransactionOrTransactionBlock(void); extern char TransactionBlockStatusCode(void); extern void AbortOutOfAnyTransaction(void); -extern void PreventTransactionChain(void *stmtNode, const char *stmtType); -extern void RequireTransactionChain(void *stmtNode, const char *stmtType); -extern bool IsInTransactionChain(void *stmtNode); +extern void PreventTransactionChain(bool isTopLevel, const char *stmtType); +extern void RequireTransactionChain(bool isTopLevel, const char *stmtType); +extern bool IsInTransactionChain(bool isTopLevel); extern void RegisterXactCallback(XactCallback callback, void *arg); extern void UnregisterXactCallback(XactCallback callback, void *arg); extern void RegisterSubXactCallback(SubXactCallback callback, void *arg); diff --git a/src/include/commands/cluster.h b/src/include/commands/cluster.h index 6929bbe2afb..0ed1e231388 100644 --- a/src/include/commands/cluster.h +++ b/src/include/commands/cluster.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994-5, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.31 2007/01/05 22:19:53 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/cluster.h,v 1.32 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,7 +17,7 @@ #include "utils/rel.h" -extern void cluster(ClusterStmt *stmt); +extern void cluster(ClusterStmt *stmt, bool isTopLevel); extern void check_index_is_clusterable(Relation OldHeap, Oid indexOid, bool recheck); diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h index cda5749603b..11ff84c57a0 100644 --- a/src/include/commands/copy.h +++ b/src/include/commands/copy.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/copy.h,v 1.29 2007/01/05 22:19:53 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/copy.h,v 1.30 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,7 +18,7 @@ #include "tcop/dest.h" -extern uint64 DoCopy(const CopyStmt *stmt); +extern uint64 DoCopy(const CopyStmt *stmt, const char *queryString); extern DestReceiver *CreateCopyDestReceiver(void); diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index 3d665ff5c2c..5bb94a24f25 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.80 2007/01/23 05:07:18 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.81 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,7 +25,6 @@ extern void DefineIndex(RangeVar *heapRelation, char *tableSpaceName, List *attributeList, Expr *predicate, - List *rangetable, List *options, bool unique, bool primary, diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h index 981064297f9..42879ce5a40 100644 --- a/src/include/commands/explain.h +++ b/src/include/commands/explain.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994-5, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.29 2007/01/05 22:19:53 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/explain.h,v 1.30 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,11 +16,16 @@ #include "executor/executor.h" -extern void ExplainQuery(ExplainStmt *stmt, ParamListInfo params, - DestReceiver *dest); +extern void ExplainQuery(ExplainStmt *stmt, const char *queryString, + ParamListInfo params, DestReceiver *dest); extern TupleDesc ExplainResultDesc(ExplainStmt *stmt); +extern void ExplainOneUtility(Node *utilityStmt, ExplainStmt *stmt, + const char *queryString, + ParamListInfo params, + TupOutputState *tstate); + extern void ExplainOnePlan(QueryDesc *queryDesc, ExplainStmt *stmt, TupOutputState *tstate); diff --git a/src/include/commands/portalcmds.h b/src/include/commands/portalcmds.h index 50fe2f13284..3d774046136 100644 --- a/src/include/commands/portalcmds.h +++ b/src/include/commands/portalcmds.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/portalcmds.h,v 1.21 2007/02/20 17:32:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/portalcmds.h,v 1.22 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -18,7 +18,8 @@ #include "utils/portal.h" -extern void PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params); +extern void PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params, + const char *queryString, bool isTopLevel); extern void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest, char *completionTag); diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h index a921bf1b045..4e27ab3bb39 100644 --- a/src/include/commands/prepare.h +++ b/src/include/commands/prepare.h @@ -6,7 +6,7 @@ * * Copyright (c) 2002-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.24 2007/02/20 17:32:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.25 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -14,58 +14,49 @@ #define PREPARE_H #include "executor/executor.h" +#include "utils/plancache.h" #include "utils/timestamp.h" /* - * The data structure representing a prepared statement + * The data structure representing a prepared statement. This is now just + * a thin veneer over a plancache entry --- the main addition is that of + * a name. * - * A prepared statement might be fully planned, or only parsed-and-rewritten. - * If fully planned, stmt_list contains PlannedStmts and/or utility statements; - * if not, it contains Query nodes. - * - * Note: all subsidiary storage lives in the context denoted by the context - * field. However, the string referenced by commandTag is not subsidiary - * storage; it is assumed to be a compile-time-constant string. As with - * portals, commandTag shall be NULL if and only if the original query string - * (before rewriting) was an empty string. + * Note: all subsidiary storage lives in the referenced plancache entry. */ typedef struct { /* dynahash.c requires key to be first field */ char stmt_name[NAMEDATALEN]; - char *query_string; /* text of query, or NULL */ - const char *commandTag; /* command tag (a constant!), or NULL */ - List *stmt_list; /* list of statement or Query nodes */ - List *argtype_list; /* list of parameter type OIDs */ - bool fully_planned; /* what is in stmt_list, exactly? */ + CachedPlanSource *plansource; /* the actual cached plan */ bool from_sql; /* prepared via SQL, not FE/BE protocol? */ TimestampTz prepare_time; /* the time when the stmt was prepared */ - MemoryContext context; /* context containing this query */ } PreparedStatement; /* Utility statements PREPARE, EXECUTE, DEALLOCATE, EXPLAIN EXECUTE */ -extern void PrepareQuery(PrepareStmt *stmt); -extern void ExecuteQuery(ExecuteStmt *stmt, ParamListInfo params, +extern void PrepareQuery(PrepareStmt *stmt, const char *queryString); +extern void ExecuteQuery(ExecuteStmt *stmt, const char *queryString, + ParamListInfo params, DestReceiver *dest, char *completionTag); extern void DeallocateQuery(DeallocateStmt *stmt); -extern void ExplainExecuteQuery(ExplainStmt *stmt, ParamListInfo params, - TupOutputState *tstate); +extern void ExplainExecuteQuery(ExecuteStmt *execstmt, ExplainStmt *stmt, + const char *queryString, + ParamListInfo params, TupOutputState *tstate); /* Low-level access to stored prepared statements */ extern void StorePreparedStatement(const char *stmt_name, + Node *raw_parse_tree, const char *query_string, const char *commandTag, + Oid *param_types, + int num_params, List *stmt_list, - List *argtype_list, - bool fully_planned, bool from_sql); extern PreparedStatement *FetchPreparedStatement(const char *stmt_name, bool throwError); extern void DropPreparedStatement(const char *stmt_name, bool showError); -extern List *FetchPreparedStatementParams(const char *stmt_name); extern TupleDesc FetchPreparedStatementResultDesc(PreparedStatement *stmt); -extern bool PreparedStatementReturnsTuples(PreparedStatement *stmt); extern List *FetchPreparedStatementTargetList(PreparedStatement *stmt); #endif /* PREPARE_H */ diff --git a/src/include/commands/schemacmds.h b/src/include/commands/schemacmds.h index e8820a8c191..e70579c3c37 100644 --- a/src/include/commands/schemacmds.h +++ b/src/include/commands/schemacmds.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/schemacmds.h,v 1.15 2007/01/05 22:19:54 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/schemacmds.h,v 1.16 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,7 +17,8 @@ #include "nodes/parsenodes.h" -extern void CreateSchemaCommand(CreateSchemaStmt *parsetree); +extern void CreateSchemaCommand(CreateSchemaStmt *parsetree, + const char *queryString); extern void RemoveSchema(List *names, DropBehavior behavior, bool missing_ok); extern void RemoveSchemaById(Oid schemaOid); diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 09da5cfc0da..b77fbf4c719 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.69 2007/01/05 22:19:54 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.70 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -110,7 +110,7 @@ extern int vacuum_freeze_min_age; /* in commands/vacuum.c */ -extern void vacuum(VacuumStmt *vacstmt, List *relids); +extern void vacuum(VacuumStmt *vacstmt, List *relids, bool isTopLevel); extern void vac_open_indexes(Relation relation, LOCKMODE lockmode, int *nindexes, Relation **Irel); extern void vac_close_indexes(int nindexes, Relation *Irel, LOCKMODE lockmode); diff --git a/src/include/commands/view.h b/src/include/commands/view.h index 2e0e5254039..ff54935bbbd 100644 --- a/src/include/commands/view.h +++ b/src/include/commands/view.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/view.h,v 1.24 2007/01/05 22:19:54 momjian Exp $ + * $PostgreSQL: pgsql/src/include/commands/view.h,v 1.25 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,7 +16,7 @@ #include "nodes/parsenodes.h" -extern void DefineView(RangeVar *view, Query *view_parse, bool replace); +extern void DefineView(ViewStmt *stmt, const char *queryString); extern void RemoveView(const RangeVar *view, DropBehavior behavior); #endif /* VIEW_H */ diff --git a/src/include/nodes/params.h b/src/include/nodes/params.h index 69bc117ef09..7a94152b422 100644 --- a/src/include/nodes/params.h +++ b/src/include/nodes/params.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/params.h,v 1.34 2007/01/05 22:19:55 momjian Exp $ + * $PostgreSQL: pgsql/src/include/nodes/params.h,v 1.35 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -82,4 +82,7 @@ typedef struct ParamExecData /* Functions found in src/backend/nodes/params.c */ extern ParamListInfo copyParamList(ParamListInfo from); +extern void getParamListTypes(ParamListInfo params, + Oid **param_types, int *num_params); + #endif /* PARAMS_H */ diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index ec9ccb6ce30..e24b57e8a23 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.341 2007/02/20 17:32:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.342 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1021,15 +1021,14 @@ typedef struct GrantRoleStmt * * We support "COPY relation FROM file", "COPY relation TO file", and * "COPY (query) TO file". In any given CopyStmt, exactly one of "relation" - * and "query" must be non-NULL. Note: "query" is a SelectStmt before - * parse analysis, and a Query afterwards. + * and "query" must be non-NULL. * ---------------------- */ typedef struct CopyStmt { NodeTag type; RangeVar *relation; /* the relation to copy */ - Query *query; /* the query to copy */ + Node *query; /* the SELECT query to copy */ List *attlist; /* List of column names (as Strings), or NIL * for all columns */ bool is_from; /* TO or FROM */ @@ -1487,8 +1486,6 @@ typedef struct IndexStmt List *indexParams; /* a list of IndexElem */ List *options; /* options from WITH clause */ Node *whereClause; /* qualification (partial-index predicate) */ - List *rangetable; /* range table for qual and/or expressions, - * filled in by transformStmt() */ bool unique; /* is index unique? */ bool primary; /* is index on primary key? */ bool isconstraint; /* is it from a CONSTRAINT clause? */ @@ -1713,7 +1710,7 @@ typedef struct ViewStmt NodeTag type; RangeVar *view; /* the view to be created */ List *aliases; /* target column names */ - Query *query; /* the SQL statement */ + Node *query; /* the SELECT query */ bool replace; /* replace an existing view? */ } ViewStmt; @@ -1805,7 +1802,7 @@ typedef struct VacuumStmt typedef struct ExplainStmt { NodeTag type; - Query *query; /* the query */ + Node *query; /* the query (as a raw parse tree) */ bool verbose; /* print plan info */ bool analyze; /* get statistics by executing plan */ } ExplainStmt; @@ -1940,9 +1937,8 @@ typedef struct PrepareStmt { NodeTag type; char *name; /* Name of plan, arbitrary */ - List *argtypes; /* Types of parameters (TypeNames) */ - List *argtype_oids; /* Types of parameters (OIDs) */ - Query *query; /* The query itself */ + List *argtypes; /* Types of parameters (List of TypeName) */ + Node *query; /* The query itself (as a raw parsetree) */ } PrepareStmt; diff --git a/src/include/parser/analyze.h b/src/include/parser/analyze.h index f53358801d9..033dce60462 100644 --- a/src/include/parser/analyze.h +++ b/src/include/parser/analyze.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.35 2007/01/05 22:19:56 momjian Exp $ + * $PostgreSQL: pgsql/src/include/parser/analyze.h,v 1.36 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -21,6 +21,10 @@ extern List *parse_analyze(Node *parseTree, const char *sourceText, extern List *parse_analyze_varparams(Node *parseTree, const char *sourceText, Oid **paramTypes, int *numParams); extern List *parse_sub_analyze(Node *parseTree, ParseState *parentParseState); + +extern IndexStmt *analyzeIndexStmt(IndexStmt *stmt, const char *queryString); +extern void analyzeRuleStmt(RuleStmt *stmt, const char *queryString, + List **actions, Node **whereClause); extern List *analyzeCreateSchemaStmt(CreateSchemaStmt *stmt); extern void CheckSelectLocking(Query *qry); extern void applyLockingClause(Query *qry, Index rtindex, diff --git a/src/include/rewrite/rewriteDefine.h b/src/include/rewrite/rewriteDefine.h index c6d15c129f6..d4673f82a6c 100644 --- a/src/include/rewrite/rewriteDefine.h +++ b/src/include/rewrite/rewriteDefine.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/rewrite/rewriteDefine.h,v 1.23 2007/01/05 22:19:57 momjian Exp $ + * $PostgreSQL: pgsql/src/include/rewrite/rewriteDefine.h,v 1.24 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,7 +16,15 @@ #include "nodes/parsenodes.h" -extern void DefineQueryRewrite(RuleStmt *args); +extern void DefineRule(RuleStmt *stmt, const char *queryString); + +extern void DefineQueryRewrite(char *rulename, + RangeVar *event_obj, + Node *event_qual, + CmdType event_type, + bool is_instead, + bool replace, + List *action); extern void RenameRewriteRule(Oid owningRel, const char *oldName, const char *newName); diff --git a/src/include/tcop/pquery.h b/src/include/tcop/pquery.h index 5cab498c13a..abf64f0ebfa 100644 --- a/src/include/tcop/pquery.h +++ b/src/include/tcop/pquery.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/tcop/pquery.h,v 1.41 2007/02/20 17:32:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/tcop/pquery.h,v 1.42 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,7 @@ extern void PortalStart(Portal portal, ParamListInfo params, extern void PortalSetResultFormat(Portal portal, int nFormats, int16 *formats); -extern bool PortalRun(Portal portal, long count, +extern bool PortalRun(Portal portal, long count, bool isTopLevel, DestReceiver *dest, DestReceiver *altdest, char *completionTag); diff --git a/src/include/tcop/utility.h b/src/include/tcop/utility.h index 52c02253068..863a664cf52 100644 --- a/src/include/tcop/utility.h +++ b/src/include/tcop/utility.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.31 2007/02/20 17:32:17 tgl Exp $ + * $PostgreSQL: pgsql/src/include/tcop/utility.h,v 1.32 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -17,8 +17,9 @@ #include "tcop/tcopprot.h" -extern void ProcessUtility(Node *parsetree, ParamListInfo params, - DestReceiver *dest, char *completionTag); +extern void ProcessUtility(Node *parsetree, const char *queryString, + ParamListInfo params, bool isTopLevel, + DestReceiver *dest, char *completionTag); extern bool UtilityReturnsTuples(Node *parsetree); diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index fd304b66ad5..f046f397e8c 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -10,7 +10,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.61 2007/01/05 22:19:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/memutils.h,v 1.62 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -75,8 +75,7 @@ extern DLLIMPORT MemoryContext MessageContext; extern DLLIMPORT MemoryContext TopTransactionContext; extern DLLIMPORT MemoryContext CurTransactionContext; -/* These two are transient links to contexts owned by other objects: */ -extern DLLIMPORT MemoryContext QueryContext; +/* This is a transient link to the active portal's memory context: */ extern DLLIMPORT MemoryContext PortalContext; diff --git a/src/include/utils/plancache.h b/src/include/utils/plancache.h new file mode 100644 index 00000000000..833ec473b13 --- /dev/null +++ b/src/include/utils/plancache.h @@ -0,0 +1,105 @@ +/*------------------------------------------------------------------------- + * + * plancache.h + * Plan cache definitions. + * + * See plancache.c for comments. + * + * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/include/utils/plancache.h,v 1.1 2007/03/13 00:33:43 tgl Exp $ + * + *------------------------------------------------------------------------- + */ +#ifndef PLANCACHE_H +#define PLANCACHE_H + +#include "access/tupdesc.h" + +/* + * CachedPlanSource represents the portion of a cached plan that persists + * across invalidation/replan cycles. It stores a raw parse tree (required), + * the original source text (optional, but highly recommended to improve + * error reports), and adjunct data. + * + * Normally, both the struct itself and the subsidiary data live in the + * context denoted by the context field, while the linked-to CachedPlan, if + * any, has its own context. Thus an invalidated CachedPlan can be dropped + * when no longer needed, and conversely a CachedPlanSource can be dropped + * without worrying whether any portals depend on particular instances of + * its plan. + * + * But for entries created by FastCreateCachedPlan, the CachedPlanSource + * and the initial version of the CachedPlan share the same memory context. + * In this case, we treat the memory context as belonging to the CachedPlan. + * The CachedPlanSource has an extra reference-counted link (orig_plan) + * to the CachedPlan, and the memory context goes away when the CachedPlan's + * reference count goes to zero. This arrangement saves overhead for plans + * that aren't expected to live long enough to need replanning, while not + * losing any flexibility if a replan turns out to be necessary. + * + * Note: the string referenced by commandTag is not subsidiary storage; + * it is assumed to be a compile-time-constant string. As with portals, + * commandTag shall be NULL if and only if the original query string (before + * rewriting) was an empty string. + */ +typedef struct CachedPlanSource +{ + Node *raw_parse_tree; /* output of raw_parser() */ + char *query_string; /* text of query, or NULL */ + const char *commandTag; /* command tag (a constant!), or NULL */ + Oid *param_types; /* array of parameter type OIDs, or NULL */ + int num_params; /* length of param_types array */ + bool fully_planned; /* do we cache planner or rewriter output? */ + bool fixed_result; /* disallow change in result tupdesc? */ + int generation; /* counter, starting at 1, for replans */ + TupleDesc resultDesc; /* result type; NULL = doesn't return tuples */ + struct CachedPlan *plan; /* link to plan, or NULL if not valid */ + MemoryContext context; /* context containing this CachedPlanSource */ + struct CachedPlan *orig_plan; /* link to plan owning my context */ +} CachedPlanSource; + +/* + * CachedPlan represents the portion of a cached plan that is discarded when + * invalidation occurs. The reference count includes both the link(s) from the + * parent CachedPlanSource, and any active plan executions, so the plan can be + * discarded exactly when refcount goes to zero. Both the struct itself and + * the subsidiary data live in the context denoted by the context field. + * This makes it easy to free a no-longer-needed cached plan. + */ +typedef struct CachedPlan +{ + List *stmt_list; /* list of statement or Query nodes */ + bool fully_planned; /* do we cache planner or rewriter output? */ + bool dead; /* if true, do not use */ + int refcount; /* count of live references to this struct */ + int generation; /* counter, starting at 1, for replans */ + MemoryContext context; /* context containing this CachedPlan */ +} CachedPlan; + + +extern void InitPlanCache(void); +extern CachedPlanSource *CreateCachedPlan(Node *raw_parse_tree, + const char *query_string, + const char *commandTag, + Oid *param_types, + int num_params, + List *stmt_list, + bool fully_planned, + bool fixed_result); +extern CachedPlanSource *FastCreateCachedPlan(Node *raw_parse_tree, + char *query_string, + const char *commandTag, + Oid *param_types, + int num_params, + List *stmt_list, + bool fully_planned, + bool fixed_result, + MemoryContext context); +extern void DropCachedPlan(CachedPlanSource *plansource); +extern CachedPlan *RevalidateCachedPlan(CachedPlanSource *plansource, + bool useResOwner); +extern void ReleaseCachedPlan(CachedPlan *plan, bool useResOwner); + +#endif /* PLANCACHE_H */ diff --git a/src/include/utils/portal.h b/src/include/utils/portal.h index aa432abb876..47651006a21 100644 --- a/src/include/utils/portal.h +++ b/src/include/utils/portal.h @@ -39,7 +39,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.73 2007/02/20 17:32:18 tgl Exp $ + * $PostgreSQL: pgsql/src/include/utils/portal.h,v 1.74 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -94,7 +94,8 @@ typedef enum PortalStrategy */ typedef enum PortalStatus { - PORTAL_NEW, /* in process of creation */ + PORTAL_NEW, /* freshly created */ + PORTAL_DEFINED, /* PortalDefineQuery done */ PORTAL_READY, /* PortalStart complete, can run it */ PORTAL_ACTIVE, /* portal is running (can't delete it) */ PORTAL_DONE, /* portal is finished (don't re-run it) */ @@ -125,15 +126,7 @@ typedef struct PortalData const char *sourceText; /* text of query, if known (may be NULL) */ const char *commandTag; /* command tag for original query */ List *stmts; /* PlannedStmts and/or utility statements */ - MemoryContext queryContext; /* where the plan trees live */ - - /* - * Note: queryContext effectively identifies which prepared statement the - * portal depends on, if any. The queryContext is *not* owned by the - * portal and is not to be deleted by portal destruction. (But for a - * cursor it is the same as "heap", and that context is deleted by portal - * destruction.) The plan trees may be in either queryContext or heap. - */ + CachedPlan *cplan; /* CachedPlan, if stmts are from one */ ParamListInfo portalParams; /* params to pass to query */ @@ -210,14 +203,13 @@ extern void AtSubCleanup_Portals(SubTransactionId mySubid); extern Portal CreatePortal(const char *name, bool allowDup, bool dupSilent); extern Portal CreateNewPortal(void); extern void PortalDrop(Portal portal, bool isTopCommit); -extern void DropDependentPortals(MemoryContext queryContext); extern Portal GetPortalByName(const char *name); extern void PortalDefineQuery(Portal portal, const char *prepStmtName, const char *sourceText, const char *commandTag, List *stmts, - MemoryContext queryContext); + CachedPlan *cplan); extern Node *PortalListGetPrimaryStmt(List *stmts); extern void PortalCreateHoldStore(Portal portal); diff --git a/src/include/utils/resowner.h b/src/include/utils/resowner.h index 663096a333f..ea0d6a74066 100644 --- a/src/include/utils/resowner.h +++ b/src/include/utils/resowner.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/resowner.h,v 1.10 2007/01/05 22:19:59 momjian Exp $ + * $PostgreSQL: pgsql/src/include/utils/resowner.h,v 1.11 2007/03/13 00:33:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -21,6 +21,7 @@ #include "storage/buf.h" #include "utils/catcache.h" +#include "utils/plancache.h" /* @@ -106,6 +107,13 @@ extern void ResourceOwnerRememberRelationRef(ResourceOwner owner, extern void ResourceOwnerForgetRelationRef(ResourceOwner owner, Relation rel); +/* support for plancache refcount management */ +extern void ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner); +extern void ResourceOwnerRememberPlanCacheRef(ResourceOwner owner, + CachedPlan *plan); +extern void ResourceOwnerForgetPlanCacheRef(ResourceOwner owner, + CachedPlan *plan); + /* support for tupledesc refcount management */ extern void ResourceOwnerEnlargeTupleDescs(ResourceOwner owner); extern void ResourceOwnerRememberTupleDesc(ResourceOwner owner, |