mirror of
https://github.com/postgres/postgres.git
synced 2025-06-07 11:02:12 +03:00
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.
This commit is contained in:
parent
f01b196597
commit
42dc4b66e6
@ -10,7 +10,7 @@
|
|||||||
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
|
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.72 2007/04/16 01:14:55 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.73 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -171,6 +171,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString)
|
|||||||
commandTag,
|
commandTag,
|
||||||
argtypes,
|
argtypes,
|
||||||
nargs,
|
nargs,
|
||||||
|
0, /* default cursor options */
|
||||||
plan_list,
|
plan_list,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
@ -435,6 +436,7 @@ StorePreparedStatement(const char *stmt_name,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool from_sql)
|
bool from_sql)
|
||||||
{
|
{
|
||||||
@ -461,6 +463,7 @@ StorePreparedStatement(const char *stmt_name,
|
|||||||
commandTag,
|
commandTag,
|
||||||
param_types,
|
param_types,
|
||||||
num_params,
|
num_params,
|
||||||
|
cursor_options,
|
||||||
stmt_list,
|
stmt_list,
|
||||||
true,
|
true,
|
||||||
true);
|
true);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.177 2007/04/16 17:21:23 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.178 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2032,6 +2032,7 @@ _SPI_save_plan(SPIPlanPtr plan)
|
|||||||
plansource->commandTag,
|
plansource->commandTag,
|
||||||
newplan->argtypes,
|
newplan->argtypes,
|
||||||
newplan->nargs,
|
newplan->nargs,
|
||||||
|
newplan->cursor_options,
|
||||||
cplan->stmt_list,
|
cplan->stmt_list,
|
||||||
true,
|
true,
|
||||||
false);
|
false);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.531 2007/04/16 01:14:57 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.532 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* this is the "main" module of the postgres backend and
|
* this is the "main" module of the postgres backend and
|
||||||
@ -1237,6 +1237,7 @@ exec_parse_message(const char *query_string, /* string to execute */
|
|||||||
commandTag,
|
commandTag,
|
||||||
paramTypes,
|
paramTypes,
|
||||||
numParams,
|
numParams,
|
||||||
|
0, /* default cursor options */
|
||||||
stmt_list,
|
stmt_list,
|
||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
@ -1261,6 +1262,7 @@ exec_parse_message(const char *query_string, /* string to execute */
|
|||||||
commandTag,
|
commandTag,
|
||||||
newParamTypes,
|
newParamTypes,
|
||||||
numParams,
|
numParams,
|
||||||
|
0, /* cursor options */
|
||||||
stmt_list,
|
stmt_list,
|
||||||
fully_planned,
|
fully_planned,
|
||||||
true,
|
true,
|
||||||
|
15
src/backend/utils/cache/plancache.c
vendored
15
src/backend/utils/cache/plancache.c
vendored
@ -33,7 +33,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.7 2007/04/16 01:14:57 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.8 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -106,6 +106,7 @@ InitPlanCache(void)
|
|||||||
* commandTag: compile-time-constant tag for query, or NULL if empty query
|
* commandTag: compile-time-constant tag for query, or NULL if empty query
|
||||||
* param_types: array of parameter type OIDs, or NULL if none
|
* param_types: array of parameter type OIDs, or NULL if none
|
||||||
* num_params: number of parameters
|
* 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
|
* stmt_list: list of PlannedStmts/utility stmts, or list of Query trees
|
||||||
* fully_planned: are we caching planner or rewriter output?
|
* fully_planned: are we caching planner or rewriter output?
|
||||||
* fixed_result: TRUE to disallow changes in result tupdesc
|
* fixed_result: TRUE to disallow changes in result tupdesc
|
||||||
@ -116,6 +117,7 @@ CreateCachedPlan(Node *raw_parse_tree,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool fully_planned,
|
bool fully_planned,
|
||||||
bool fixed_result)
|
bool fixed_result)
|
||||||
@ -157,6 +159,7 @@ CreateCachedPlan(Node *raw_parse_tree,
|
|||||||
else
|
else
|
||||||
plansource->param_types = NULL;
|
plansource->param_types = NULL;
|
||||||
plansource->num_params = num_params;
|
plansource->num_params = num_params;
|
||||||
|
plansource->cursor_options = cursor_options;
|
||||||
plansource->fully_planned = fully_planned;
|
plansource->fully_planned = fully_planned;
|
||||||
plansource->fixed_result = fixed_result;
|
plansource->fixed_result = fixed_result;
|
||||||
plansource->search_path = search_path;
|
plansource->search_path = search_path;
|
||||||
@ -212,6 +215,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool fully_planned,
|
bool fully_planned,
|
||||||
bool fixed_result,
|
bool fixed_result,
|
||||||
@ -237,6 +241,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
|
|||||||
plansource->commandTag = commandTag; /* no copying needed */
|
plansource->commandTag = commandTag; /* no copying needed */
|
||||||
plansource->param_types = param_types;
|
plansource->param_types = param_types;
|
||||||
plansource->num_params = num_params;
|
plansource->num_params = num_params;
|
||||||
|
plansource->cursor_options = cursor_options;
|
||||||
plansource->fully_planned = fully_planned;
|
plansource->fully_planned = fully_planned;
|
||||||
plansource->fixed_result = fixed_result;
|
plansource->fixed_result = fixed_result;
|
||||||
plansource->search_path = search_path;
|
plansource->search_path = search_path;
|
||||||
@ -458,13 +463,11 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner)
|
|||||||
if (plansource->fully_planned)
|
if (plansource->fully_planned)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Generate plans for queries. We don't need any boundParams, and
|
* Generate plans for queries. Assume snapshot is not set yet
|
||||||
* 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
|
|
||||||
* (XXX this may be wasteful, won't all callers have done that?)
|
* (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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
|
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.26 2007/04/12 06:53:48 neilc Exp $
|
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.27 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -51,6 +51,7 @@ extern void StorePreparedStatement(const char *stmt_name,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool from_sql);
|
bool from_sql);
|
||||||
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
|
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/plancache.h,v 1.5 2007/04/12 06:53:48 neilc Exp $
|
* $PostgreSQL: pgsql/src/include/utils/plancache.h,v 1.6 2007/04/16 18:21:07 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -51,6 +51,7 @@ typedef struct CachedPlanSource
|
|||||||
const char *commandTag; /* command tag (a constant!), or NULL */
|
const char *commandTag; /* command tag (a constant!), or NULL */
|
||||||
Oid *param_types; /* array of parameter type OIDs, or NULL */
|
Oid *param_types; /* array of parameter type OIDs, or NULL */
|
||||||
int num_params; /* length of param_types array */
|
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 fully_planned; /* do we cache planner or rewriter output? */
|
||||||
bool fixed_result; /* disallow change in result tupdesc? */
|
bool fixed_result; /* disallow change in result tupdesc? */
|
||||||
struct OverrideSearchPath *search_path; /* saved search_path */
|
struct OverrideSearchPath *search_path; /* saved search_path */
|
||||||
@ -86,6 +87,7 @@ extern CachedPlanSource *CreateCachedPlan(Node *raw_parse_tree,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool fully_planned,
|
bool fully_planned,
|
||||||
bool fixed_result);
|
bool fixed_result);
|
||||||
@ -94,6 +96,7 @@ extern CachedPlanSource *FastCreateCachedPlan(Node *raw_parse_tree,
|
|||||||
const char *commandTag,
|
const char *commandTag,
|
||||||
Oid *param_types,
|
Oid *param_types,
|
||||||
int num_params,
|
int num_params,
|
||||||
|
int cursor_options,
|
||||||
List *stmt_list,
|
List *stmt_list,
|
||||||
bool fully_planned,
|
bool fully_planned,
|
||||||
bool fixed_result,
|
bool fixed_result,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user