summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2007-04-16 18:21:07 +0000
committerTom Lane2007-04-16 18:21:07 +0000
commit7b897b8aaf798acc33756f7034eedb4feee5efac (patch)
tree189f45e096ad5f92263845541a1a45f410fb1535
parentf2464a7112725e792220f128b2d7af7cb091b810 (diff)
Make plancache store cursor options so it can pass them to planner during
a replan. I had originally thought this was not necessary, but the new SPI facilities create a path whereby queries planned with non-default options can get into the cache, so it is necessary.
-rw-r--r--src/backend/commands/prepare.c3
-rw-r--r--src/backend/executor/spi.c1
-rw-r--r--src/backend/tcop/postgres.c2
-rw-r--r--src/backend/utils/cache/plancache.c13
-rw-r--r--src/include/commands/prepare.h1
-rw-r--r--src/include/utils/plancache.h3
6 files changed, 18 insertions, 5 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 7c1dded914..cc41812243 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -171,6 +171,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString)
commandTag,
argtypes,
nargs,
+ 0, /* default cursor options */
plan_list,
true);
}
@@ -435,6 +436,7 @@ StorePreparedStatement(const char *stmt_name,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool from_sql)
{
@@ -461,6 +463,7 @@ StorePreparedStatement(const char *stmt_name,
commandTag,
param_types,
num_params,
+ cursor_options,
stmt_list,
true,
true);
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 65750da90d..59f1b992da 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2032,6 +2032,7 @@ _SPI_save_plan(SPIPlanPtr plan)
plansource->commandTag,
newplan->argtypes,
newplan->nargs,
+ newplan->cursor_options,
cplan->stmt_list,
true,
false);
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 030f73eec9..405f004e2b 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -1237,6 +1237,7 @@ exec_parse_message(const char *query_string, /* string to execute */
commandTag,
paramTypes,
numParams,
+ 0, /* default cursor options */
stmt_list,
false);
}
@@ -1261,6 +1262,7 @@ exec_parse_message(const char *query_string, /* string to execute */
commandTag,
newParamTypes,
numParams,
+ 0, /* cursor options */
stmt_list,
fully_planned,
true,
diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c
index 307f5d6c60..1b5fbfb874 100644
--- a/src/backend/utils/cache/plancache.c
+++ b/src/backend/utils/cache/plancache.c
@@ -106,6 +106,7 @@ InitPlanCache(void)
* commandTag: compile-time-constant tag for query, or NULL if empty query
* param_types: array of parameter type OIDs, or NULL if none
* num_params: number of parameters
+ * cursor_options: options bitmask that was/will be passed to planner
* stmt_list: list of PlannedStmts/utility stmts, or list of Query trees
* fully_planned: are we caching planner or rewriter output?
* fixed_result: TRUE to disallow changes in result tupdesc
@@ -116,6 +117,7 @@ CreateCachedPlan(Node *raw_parse_tree,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool fully_planned,
bool fixed_result)
@@ -157,6 +159,7 @@ CreateCachedPlan(Node *raw_parse_tree,
else
plansource->param_types = NULL;
plansource->num_params = num_params;
+ plansource->cursor_options = cursor_options;
plansource->fully_planned = fully_planned;
plansource->fixed_result = fixed_result;
plansource->search_path = search_path;
@@ -212,6 +215,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool fully_planned,
bool fixed_result,
@@ -237,6 +241,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
plansource->commandTag = commandTag; /* no copying needed */
plansource->param_types = param_types;
plansource->num_params = num_params;
+ plansource->cursor_options = cursor_options;
plansource->fully_planned = fully_planned;
plansource->fixed_result = fixed_result;
plansource->search_path = search_path;
@@ -458,13 +463,11 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner)
if (plansource->fully_planned)
{
/*
- * Generate plans for queries. We don't need any boundParams, and
- * currently we don't need to worry about cursor options because
- * cursor plans are never saved in the plancache (that might have
- * to change someday). Also, assume snapshot is not set yet
+ * Generate plans for queries. Assume snapshot is not set yet
* (XXX this may be wasteful, won't all callers have done that?)
*/
- slist = pg_plan_queries(slist, 0, NULL, true);
+ slist = pg_plan_queries(slist, plansource->cursor_options, NULL,
+ true);
}
/*
diff --git a/src/include/commands/prepare.h b/src/include/commands/prepare.h
index 6cc1542433..03b44814a8 100644
--- a/src/include/commands/prepare.h
+++ b/src/include/commands/prepare.h
@@ -51,6 +51,7 @@ extern void StorePreparedStatement(const char *stmt_name,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool from_sql);
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
diff --git a/src/include/utils/plancache.h b/src/include/utils/plancache.h
index 4055bcccfa..d3502b707d 100644
--- a/src/include/utils/plancache.h
+++ b/src/include/utils/plancache.h
@@ -51,6 +51,7 @@ typedef struct CachedPlanSource
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 */
+ int cursor_options; /* cursor options used for planning */
bool fully_planned; /* do we cache planner or rewriter output? */
bool fixed_result; /* disallow change in result tupdesc? */
struct OverrideSearchPath *search_path; /* saved search_path */
@@ -86,6 +87,7 @@ extern CachedPlanSource *CreateCachedPlan(Node *raw_parse_tree,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool fully_planned,
bool fixed_result);
@@ -94,6 +96,7 @@ extern CachedPlanSource *FastCreateCachedPlan(Node *raw_parse_tree,
const char *commandTag,
Oid *param_types,
int num_params,
+ int cursor_options,
List *stmt_list,
bool fully_planned,
bool fixed_result,