Make plancache store cursor options so it can pass them to planner during
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 16 Apr 2007 18:21:07 +0000 (18:21 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 16 Apr 2007 18:21:07 +0000 (18:21 +0000)
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.

src/backend/commands/prepare.c
src/backend/executor/spi.c
src/backend/tcop/postgres.c
src/backend/utils/cache/plancache.c
src/include/commands/prepare.h
src/include/utils/plancache.h

index 7c1dded9146aa9bd6cb90fbe31d30614b8b5d012..cc418122435802ed22a0ba582e0b5c116dabeb92 100644 (file)
@@ -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);
index 65750da90da9569d4bc3ca15e384a1096820fa69..59f1b992da5c909dedb434558550d60380d057ea 100644 (file)
@@ -2032,6 +2032,7 @@ _SPI_save_plan(SPIPlanPtr plan)
                                                                         plansource->commandTag,
                                                                         newplan->argtypes,
                                                                         newplan->nargs,
+                                                                        newplan->cursor_options,
                                                                         cplan->stmt_list,
                                                                         true,
                                                                         false);
index 030f73eec9e0a91338e7cc18be57e40e88737351..405f004e2b684170b7b41a6300819e7599705047 100644 (file)
@@ -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,
index 307f5d6c6091204d0c7bfdad3c2980bc9758c14a..1b5fbfb874f54d0cf7a7a1d596418eee6662cf3e 100644 (file)
@@ -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);
                }
 
                /*
index 6cc1542433278b1f7abb8313951cca7add170651..03b44814a8cd02415e0a6b4039b099f064341add 100644 (file)
@@ -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,
index 4055bcccfaeb16f6932ab6ecbf1b3a0554f822c4..d3502b707de34930fdd1d7c4f5125cd87a8fb550 100644 (file)
@@ -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,