diff options
| author | Tom Lane | 2007-03-13 00:33:44 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-03-13 00:33:44 +0000 |
| commit | b9527e984092e838790b543b014c0c2720ea4f11 (patch) | |
| tree | 60a6063280d446701e1b93e1149eaeb9ce13a128 /src/include/commands | |
| parent | f84308f1958313f6cd1644d74b6a8ff49a871f8d (diff) | |
First phase of plan-invalidation project: create a plan cache management
module and teach PREPARE and protocol-level prepared statements to use it.
In service of this, rearrange utility-statement processing so that parse
analysis does not assume table schemas can't change before execution for
utility statements (necessary because we don't attempt to re-acquire locks
for utility statements when reusing a stored plan). This requires some
refactoring of the ProcessUtility API, but it ends up cleaner anyway,
for instance we can get rid of the QueryContext global.
Still to do: fix up SPI and related code to use the plan cache; I'm tempted to
try to make SQL functions use it too. Also, there are at least some aspects
of system state that we want to ensure remain the same during a replan as in
the original processing; search_path certainly ought to behave that way for
instance, and perhaps there are others.
Diffstat (limited to 'src/include/commands')
| -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 |
9 files changed, 39 insertions, 42 deletions
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 */ |
