Skip to content

Commit 42dc4b6

Browse files
committed
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.
1 parent f01b196 commit 42dc4b6

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/backend/commands/prepare.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.72 2007/04/16 01:14:55 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.73 2007/04/16 18:21:07 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -171,6 +171,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString)
171171
commandTag,
172172
argtypes,
173173
nargs,
174+
0, /* default cursor options */
174175
plan_list,
175176
true);
176177
}
@@ -435,6 +436,7 @@ StorePreparedStatement(const char *stmt_name,
435436
const char *commandTag,
436437
Oid *param_types,
437438
int num_params,
439+
int cursor_options,
438440
List *stmt_list,
439441
bool from_sql)
440442
{
@@ -461,6 +463,7 @@ StorePreparedStatement(const char *stmt_name,
461463
commandTag,
462464
param_types,
463465
num_params,
466+
cursor_options,
464467
stmt_list,
465468
true,
466469
true);

src/backend/executor/spi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.177 2007/04/16 17:21:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/spi.c,v 1.178 2007/04/16 18:21:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2032,6 +2032,7 @@ _SPI_save_plan(SPIPlanPtr plan)
20322032
plansource->commandTag,
20332033
newplan->argtypes,
20342034
newplan->nargs,
2035+
newplan->cursor_options,
20352036
cplan->stmt_list,
20362037
true,
20372038
false);

src/backend/tcop/postgres.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.531 2007/04/16 01:14:57 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.532 2007/04/16 18:21:07 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1237,6 +1237,7 @@ exec_parse_message(const char *query_string, /* string to execute */
12371237
commandTag,
12381238
paramTypes,
12391239
numParams,
1240+
0, /* default cursor options */
12401241
stmt_list,
12411242
false);
12421243
}
@@ -1261,6 +1262,7 @@ exec_parse_message(const char *query_string, /* string to execute */
12611262
commandTag,
12621263
newParamTypes,
12631264
numParams,
1265+
0, /* cursor options */
12641266
stmt_list,
12651267
fully_planned,
12661268
true,

src/backend/utils/cache/plancache.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* Portions Copyright (c) 1994, Regents of the University of California
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.7 2007/04/16 01:14:57 tgl Exp $
36+
* $PostgreSQL: pgsql/src/backend/utils/cache/plancache.c,v 1.8 2007/04/16 18:21:07 tgl Exp $
3737
*
3838
*-------------------------------------------------------------------------
3939
*/
@@ -106,6 +106,7 @@ InitPlanCache(void)
106106
* commandTag: compile-time-constant tag for query, or NULL if empty query
107107
* param_types: array of parameter type OIDs, or NULL if none
108108
* num_params: number of parameters
109+
* cursor_options: options bitmask that was/will be passed to planner
109110
* stmt_list: list of PlannedStmts/utility stmts, or list of Query trees
110111
* fully_planned: are we caching planner or rewriter output?
111112
* fixed_result: TRUE to disallow changes in result tupdesc
@@ -116,6 +117,7 @@ CreateCachedPlan(Node *raw_parse_tree,
116117
const char *commandTag,
117118
Oid *param_types,
118119
int num_params,
120+
int cursor_options,
119121
List *stmt_list,
120122
bool fully_planned,
121123
bool fixed_result)
@@ -157,6 +159,7 @@ CreateCachedPlan(Node *raw_parse_tree,
157159
else
158160
plansource->param_types = NULL;
159161
plansource->num_params = num_params;
162+
plansource->cursor_options = cursor_options;
160163
plansource->fully_planned = fully_planned;
161164
plansource->fixed_result = fixed_result;
162165
plansource->search_path = search_path;
@@ -212,6 +215,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
212215
const char *commandTag,
213216
Oid *param_types,
214217
int num_params,
218+
int cursor_options,
215219
List *stmt_list,
216220
bool fully_planned,
217221
bool fixed_result,
@@ -237,6 +241,7 @@ FastCreateCachedPlan(Node *raw_parse_tree,
237241
plansource->commandTag = commandTag; /* no copying needed */
238242
plansource->param_types = param_types;
239243
plansource->num_params = num_params;
244+
plansource->cursor_options = cursor_options;
240245
plansource->fully_planned = fully_planned;
241246
plansource->fixed_result = fixed_result;
242247
plansource->search_path = search_path;
@@ -458,13 +463,11 @@ RevalidateCachedPlan(CachedPlanSource *plansource, bool useResOwner)
458463
if (plansource->fully_planned)
459464
{
460465
/*
461-
* Generate plans for queries. We don't need any boundParams, and
462-
* currently we don't need to worry about cursor options because
463-
* cursor plans are never saved in the plancache (that might have
464-
* to change someday). Also, assume snapshot is not set yet
466+
* Generate plans for queries. Assume snapshot is not set yet
465467
* (XXX this may be wasteful, won't all callers have done that?)
466468
*/
467-
slist = pg_plan_queries(slist, 0, NULL, true);
469+
slist = pg_plan_queries(slist, plansource->cursor_options, NULL,
470+
true);
468471
}
469472

470473
/*

src/include/commands/prepare.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.26 2007/04/12 06:53:48 neilc Exp $
9+
* $PostgreSQL: pgsql/src/include/commands/prepare.h,v 1.27 2007/04/16 18:21:07 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -51,6 +51,7 @@ extern void StorePreparedStatement(const char *stmt_name,
5151
const char *commandTag,
5252
Oid *param_types,
5353
int num_params,
54+
int cursor_options,
5455
List *stmt_list,
5556
bool from_sql);
5657
extern PreparedStatement *FetchPreparedStatement(const char *stmt_name,

src/include/utils/plancache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/utils/plancache.h,v 1.5 2007/04/12 06:53:48 neilc Exp $
11+
* $PostgreSQL: pgsql/src/include/utils/plancache.h,v 1.6 2007/04/16 18:21:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -51,6 +51,7 @@ typedef struct CachedPlanSource
5151
const char *commandTag; /* command tag (a constant!), or NULL */
5252
Oid *param_types; /* array of parameter type OIDs, or NULL */
5353
int num_params; /* length of param_types array */
54+
int cursor_options; /* cursor options used for planning */
5455
bool fully_planned; /* do we cache planner or rewriter output? */
5556
bool fixed_result; /* disallow change in result tupdesc? */
5657
struct OverrideSearchPath *search_path; /* saved search_path */
@@ -86,6 +87,7 @@ extern CachedPlanSource *CreateCachedPlan(Node *raw_parse_tree,
8687
const char *commandTag,
8788
Oid *param_types,
8889
int num_params,
90+
int cursor_options,
8991
List *stmt_list,
9092
bool fully_planned,
9193
bool fixed_result);
@@ -94,6 +96,7 @@ extern CachedPlanSource *FastCreateCachedPlan(Node *raw_parse_tree,
9496
const char *commandTag,
9597
Oid *param_types,
9698
int num_params,
99+
int cursor_options,
97100
List *stmt_list,
98101
bool fully_planned,
99102
bool fixed_result,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy