1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* tlist.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* prototypes for tlist.c.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
2015-01-06 17:43:47 +01:00
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/optimizer/tlist.h
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TLIST_H
|
|
|
|
#define TLIST_H
|
|
|
|
|
Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window.
Regular aggregate functions in combination with, or within the arguments
of, window functions are OK per spec; they have the semantics that the
aggregate output rows are computed and then we run the window functions
over that row set. (Thus, this combination is not really useful unless
there's a GROUP BY so that more than one aggregate output row is possible.)
The case without GROUP BY could fail, as recently reported by Jeff Davis,
because sloppy construction of the Agg node's targetlist resulted in extra
references to possibly-ungrouped Vars appearing outside the aggregate
function calls themselves. See the added regression test case for an
example.
Fixing this requires modifying the API of flatten_tlist and its underlying
function pull_var_clause. I chose to make pull_var_clause's API for
aggregates identical to what it was already doing for placeholders, since
the useful behaviors turn out to be the same (error, report node as-is, or
recurse into it). I also tightened the error checking in this area a bit:
if it was ever valid to see an uplevel Var, Aggref, or PlaceHolderVar here,
that was a long time ago, so complain instead of ignoring them.
Backpatch into 9.1. The failure exists in 8.4 and 9.0 as well, but seeing
that it only occurs in a basically-useless corner case, it doesn't seem
worth the risks of changing a function API in a minor release. There might
be third-party code using pull_var_clause.
2011-07-13 00:23:55 +02:00
|
|
|
#include "optimizer/var.h"
|
1997-11-26 02:14:33 +01:00
|
|
|
|
2003-06-30 01:05:05 +02:00
|
|
|
|
2005-04-06 18:34:07 +02:00
|
|
|
extern TargetEntry *tlist_member(Node *node, List *targetlist);
|
2007-11-08 20:25:37 +01:00
|
|
|
extern TargetEntry *tlist_member_ignore_relabel(Node *node, List *targetlist);
|
2013-08-23 23:30:53 +02:00
|
|
|
extern TargetEntry *tlist_member_match_var(Var *var, List *targetlist);
|
1996-07-09 08:22:35 +02:00
|
|
|
|
Avoid listing ungrouped Vars in the targetlist of Agg-underneath-Window.
Regular aggregate functions in combination with, or within the arguments
of, window functions are OK per spec; they have the semantics that the
aggregate output rows are computed and then we run the window functions
over that row set. (Thus, this combination is not really useful unless
there's a GROUP BY so that more than one aggregate output row is possible.)
The case without GROUP BY could fail, as recently reported by Jeff Davis,
because sloppy construction of the Agg node's targetlist resulted in extra
references to possibly-ungrouped Vars appearing outside the aggregate
function calls themselves. See the added regression test case for an
example.
Fixing this requires modifying the API of flatten_tlist and its underlying
function pull_var_clause. I chose to make pull_var_clause's API for
aggregates identical to what it was already doing for placeholders, since
the useful behaviors turn out to be the same (error, report node as-is, or
recurse into it). I also tightened the error checking in this area a bit:
if it was ever valid to see an uplevel Var, Aggref, or PlaceHolderVar here,
that was a long time ago, so complain instead of ignoring them.
Backpatch into 9.1. The failure exists in 8.4 and 9.0 as well, but seeing
that it only occurs in a basically-useless corner case, it doesn't seem
worth the risks of changing a function API in a minor release. There might
be third-party code using pull_var_clause.
2011-07-13 00:23:55 +02:00
|
|
|
extern List *flatten_tlist(List *tlist, PVCAggregateBehavior aggbehavior,
|
|
|
|
PVCPlaceHolderBehavior phbehavior);
|
2008-12-28 19:54:01 +01:00
|
|
|
extern List *add_to_flat_tlist(List *tlist, List *exprs);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2008-08-07 21:35:02 +02:00
|
|
|
extern List *get_tlist_exprs(List *tlist, bool includeJunk);
|
2013-03-14 18:42:51 +01:00
|
|
|
|
Implement UPDATE tab SET (col1,col2,...) = (SELECT ...), ...
This SQL-standard feature allows a sub-SELECT yielding multiple columns
(but only one row) to be used to compute the new values of several columns
to be updated. While the same results can be had with an independent
sub-SELECT per column, such a workaround can require a great deal of
duplicated computation.
The standard actually says that the source for a multi-column assignment
could be any row-valued expression. The implementation used here is
tightly tied to our existing sub-SELECT support and can't handle other
cases; the Bison grammar would have some issues with them too. However,
I don't feel too bad about this since other cases can be converted into
sub-SELECTs. For instance, "SET (a,b,c) = row_valued_function(x)" could
be written "SET (a,b,c) = (SELECT * FROM row_valued_function(x))".
2014-06-18 19:22:25 +02:00
|
|
|
extern int count_nonjunk_tlist_entries(List *tlist);
|
|
|
|
|
2013-03-14 18:42:51 +01:00
|
|
|
extern bool tlist_same_exprs(List *tlist1, List *tlist2);
|
|
|
|
|
2008-08-07 21:35:02 +02:00
|
|
|
extern bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK);
|
2011-04-16 22:39:50 +02:00
|
|
|
extern bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK);
|
2008-08-07 21:35:02 +02:00
|
|
|
|
2007-11-08 22:49:48 +01:00
|
|
|
extern TargetEntry *get_sortgroupref_tle(Index sortref,
|
2007-11-15 22:14:46 +01:00
|
|
|
List *targetList);
|
2008-08-02 23:32:01 +02:00
|
|
|
extern TargetEntry *get_sortgroupclause_tle(SortGroupClause *sgClause,
|
2000-04-12 19:17:23 +02:00
|
|
|
List *targetList);
|
2008-08-02 23:32:01 +02:00
|
|
|
extern Node *get_sortgroupclause_expr(SortGroupClause *sgClause,
|
2000-04-12 19:17:23 +02:00
|
|
|
List *targetList);
|
2008-08-02 23:32:01 +02:00
|
|
|
extern List *get_sortgrouplist_exprs(List *sgClauses,
|
2003-08-04 02:43:34 +02:00
|
|
|
List *targetList);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2008-08-07 03:11:52 +02:00
|
|
|
extern Oid *extract_grouping_ops(List *groupClause);
|
|
|
|
extern AttrNumber *extract_grouping_cols(List *groupClause, List *tlist);
|
|
|
|
extern bool grouping_is_sortable(List *groupClause);
|
|
|
|
extern bool grouping_is_hashable(List *groupClause);
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* TLIST_H */
|