summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2003-06-06 15:04:03 +0000
committerTom Lane2003-06-06 15:04:03 +0000
commite649796f128bd8702ba5744d36f4e8cb81f0b754 (patch)
tree050eda51ad8f0298731316ccf61db2c01a2863a3 /src/include
parent2c93861f7cef99b4613abd37ed7e4c15a95754b4 (diff)
Implement outer-level aggregates to conform to the SQL spec, with
extensions to support our historical behavior. An aggregate belongs to the closest query level of any of the variables in its argument, or the current query level if there are no variables (e.g., COUNT(*)). The implementation involves adding an agglevelsup field to Aggref, and treating outer aggregates like outer variables at planning time.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/catversion.h4
-rw-r--r--src/include/nodes/primnodes.h3
-rw-r--r--src/include/optimizer/subselect.h5
-rw-r--r--src/include/optimizer/var.h3
-rw-r--r--src/include/parser/parse_agg.h4
5 files changed, 12 insertions, 7 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index 443af8e8d6a..209bd5ff242 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: catversion.h,v 1.197 2003/05/28 16:03:59 tgl Exp $
+ * $Id: catversion.h,v 1.198 2003/06/06 15:04:02 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200305271
+#define CATALOG_VERSION_NO 200306051
#endif
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index 558621c9006..12af0fd0925 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: primnodes.h,v 1.82 2003/05/06 00:20:33 tgl Exp $
+ * $Id: primnodes.h,v 1.83 2003/06/06 15:04:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -223,6 +223,7 @@ typedef struct Aggref
Oid aggfnoid; /* pg_proc Oid of the aggregate */
Oid aggtype; /* type Oid of result of the aggregate */
Expr *target; /* expression we are aggregating on */
+ Index agglevelsup; /* > 0 if agg belongs to outer query */
bool aggstar; /* TRUE if argument was really '*' */
bool aggdistinct; /* TRUE if it's agg(DISTINCT ...) */
} Aggref;
diff --git a/src/include/optimizer/subselect.h b/src/include/optimizer/subselect.h
index 9dce88e0a8d..c3c7462d04a 100644
--- a/src/include/optimizer/subselect.h
+++ b/src/include/optimizer/subselect.h
@@ -5,18 +5,19 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: subselect.h,v 1.18 2003/02/09 00:30:41 tgl Exp $
+ * $Id: subselect.h,v 1.19 2003/06/06 15:04:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef SUBSELECT_H
#define SUBSELECT_H
+#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
extern Index PlannerQueryLevel; /* level of current query */
extern List *PlannerInitPlan; /* init subplans for current query */
-extern List *PlannerParamVar; /* to get Var from Param->paramid */
+extern List *PlannerParamList; /* to keep track of cross-level Params */
extern int PlannerPlanId; /* to assign unique ID to subquery plans */
extern Node *convert_IN_to_join(Query *parse, SubLink *sublink);
diff --git a/src/include/optimizer/var.h b/src/include/optimizer/var.h
index 3c84020ef92..82124627f78 100644
--- a/src/include/optimizer/var.h
+++ b/src/include/optimizer/var.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: var.h,v 1.26 2003/02/08 20:20:55 tgl Exp $
+ * $Id: var.h,v 1.27 2003/06/06 15:04:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,6 +24,7 @@ extern bool contain_whole_tuple_var(Node *node, int varno, int levelsup);
extern bool contain_var_clause(Node *node);
extern bool contain_vars_of_level(Node *node, int levelsup);
extern bool contain_vars_above_level(Node *node, int levelsup);
+extern int find_minimum_var_level(Node *node);
extern List *pull_var_clause(Node *node, bool includeUpperVars);
extern Node *flatten_join_alias_vars(Query *root, Node *node);
diff --git a/src/include/parser/parse_agg.h b/src/include/parser/parse_agg.h
index 111d726bc9c..bc1e601cc22 100644
--- a/src/include/parser/parse_agg.h
+++ b/src/include/parser/parse_agg.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parse_agg.h,v 1.25 2003/01/17 03:25:04 tgl Exp $
+ * $Id: parse_agg.h,v 1.26 2003/06/06 15:04:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,6 +15,8 @@
#include "parser/parse_node.h"
+extern void transformAggregateCall(ParseState *pstate, Aggref *agg);
+
extern void parseCheckAggregates(ParseState *pstate, Query *qry);
#endif /* PARSE_AGG_H */