summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/setrefs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-01-15 22:36:35 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-01-15 22:36:35 +0000
commit08f8d478ebc37e42f3ced07d17dae83d6a9a3810 (patch)
treeaedef12bd96c3a789c72ae38e3cfab39801d4556 /src/backend/optimizer/plan/setrefs.c
parent00b5ccebdd0d2925a2e5db0fdf067ea4b7bae799 (diff)
Do parse analysis of an EXPLAIN's contained statement during the normal
parse analysis phase, rather than at execution time. This makes parameter handling work the same as it does in ordinary plannable queries, and in particular fixes the incompatibility that Pavel pointed out with plpgsql's new handling of variable references. plancache.c gets a little bit grottier, but the alternatives seem worse.
Diffstat (limited to 'src/backend/optimizer/plan/setrefs.c')
-rw-r--r--src/backend/optimizer/plan/setrefs.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 2c33e6acb98..aa4fd4e1ebe 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.156 2010/01/02 16:57:47 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.157 2010/01/15 22:36:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1905,14 +1905,15 @@ record_plan_function_dependency(PlannerGlobal *glob, Oid funcid)
/*
* extract_query_dependencies
- * Given a list of not-yet-planned queries (i.e. Query nodes),
- * extract their dependencies just as set_plan_references would do.
+ * Given a not-yet-planned query or queries (i.e. a Query node or list
+ * of Query nodes), extract dependencies just as set_plan_references
+ * would do.
*
* This is needed by plancache.c to handle invalidation of cached unplanned
* queries.
*/
void
-extract_query_dependencies(List *queries,
+extract_query_dependencies(Node *query,
List **relationOids,
List **invalItems)
{
@@ -1924,7 +1925,7 @@ extract_query_dependencies(List *queries,
glob.relationOids = NIL;
glob.invalItems = NIL;
- (void) extract_query_dependencies_walker((Node *) queries, &glob);
+ (void) extract_query_dependencies_walker(query, &glob);
*relationOids = glob.relationOids;
*invalItems = glob.invalItems;
@@ -1943,6 +1944,19 @@ extract_query_dependencies_walker(Node *node, PlannerGlobal *context)
Query *query = (Query *) node;
ListCell *lc;
+ if (query->commandType == CMD_UTILITY)
+ {
+ /* Ignore utility statements, except EXPLAIN */
+ if (IsA(query->utilityStmt, ExplainStmt))
+ {
+ query = (Query *) ((ExplainStmt *) query->utilityStmt)->query;
+ Assert(IsA(query, Query));
+ Assert(query->commandType != CMD_UTILITY);
+ }
+ else
+ return false;
+ }
+
/* Collect relation OIDs in this Query's rtable */
foreach(lc, query->rtable)
{