as per my recent proposal: 1. Fold SortClause and GroupClause into a single node type SortGroupClause. We were already relying on them to be struct-equivalent, so using two node tags wasn't accomplishing much except to get in the way of comparing items with equal(). 2. Add an "eqop" field to SortGroupClause to carry the associated equality operator. This is cheap for the parser to get at the same time it's looking up the sort operator, and storing it eliminates the need for repeated not-so-cheap lookups during planning. In future this will also let us represent GROUP/DISTINCT operations on datatypes that have hash opclasses but no btree opclasses (ie, they have equality but no natural sort order). The previous representation simply didn't work for that, since its only indicator of comparison semantics was a sort operator. 3. Add a hasDistinctOn boolean to struct Query to explicitly record whether the distinctClause came from DISTINCT or DISTINCT ON. This allows removing some complicated and not 100% bulletproof code that attempted to figure that out from the distinctClause alone. This patch doesn't in itself create any new capability, but it's necessary infrastructure for future attempts to use hash-based grouping for DISTINCT and UNION/INTERSECT/EXCEPT.
45 lines
1.8 KiB
C
45 lines
1.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* parse_clause.h
|
|
* handle clauses in parser
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* $PostgreSQL: pgsql/src/include/parser/parse_clause.h,v 1.51 2008/08/02 21:32:01 tgl Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef PARSE_CLAUSE_H
|
|
#define PARSE_CLAUSE_H
|
|
|
|
#include "parser/parse_node.h"
|
|
|
|
extern void transformFromClause(ParseState *pstate, List *frmList);
|
|
extern int setTargetTable(ParseState *pstate, RangeVar *relation,
|
|
bool inh, bool alsoSource, AclMode requiredPerms);
|
|
extern bool interpretInhOption(InhOption inhOpt);
|
|
extern bool interpretOidsOption(List *defList);
|
|
|
|
extern Node *transformWhereClause(ParseState *pstate, Node *clause,
|
|
const char *constructName);
|
|
extern Node *transformLimitClause(ParseState *pstate, Node *clause,
|
|
const char *constructName);
|
|
extern List *transformGroupClause(ParseState *pstate, List *grouplist,
|
|
List **targetlist, List *sortClause);
|
|
extern List *transformSortClause(ParseState *pstate, List *orderlist,
|
|
List **targetlist, bool resolveUnknown);
|
|
extern List *transformDistinctClause(ParseState *pstate,
|
|
List **targetlist, List *sortClause);
|
|
extern List *transformDistinctOnClause(ParseState *pstate, List *distinctlist,
|
|
List **targetlist, List *sortClause);
|
|
|
|
extern List *addTargetToGroupList(ParseState *pstate, TargetEntry *tle,
|
|
List *grouplist, List *targetlist,
|
|
bool requireSortOp, bool resolveUnknown);
|
|
extern Index assignSortGroupRef(TargetEntry *tle, List *tlist);
|
|
extern bool targetIsInSortList(TargetEntry *tle, Oid sortop, List *sortList);
|
|
|
|
#endif /* PARSE_CLAUSE_H */
|