mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Redesign DISTINCT ON as discussed in pgsql-sql 1/25/00: syntax is now
SELECT DISTINCT ON (expr [, expr ...]) targetlist ... and there is a check to make sure that the user didn't specify an ORDER BY that's incompatible with the DISTINCT operation. Reimplement nodeUnique and nodeGroup to use the proper datatype-specific equality function for each column being compared --- they used to do bitwise comparisons or convert the data to text strings and strcmp(). (To add insult to injury, they'd look up the conversion functions once for each tuple...) Parse/plan representation of DISTINCT is now a list of SortClause nodes. initdb forced by querytree change...
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.42 2000/01/26 05:56:40 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.43 2000/01/27 18:11:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -216,6 +216,33 @@ get_expr(TargetEntry *tle)
|
||||
return (Var *) tle->expr;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_sortgroupclause_tle
|
||||
* Find the targetlist entry matching the given SortClause
|
||||
* (or GroupClause) by ressortgroupref, and return it.
|
||||
*
|
||||
* Because GroupClause is typedef'd as SortClause, either kind of
|
||||
* node can be passed without casting.
|
||||
*/
|
||||
TargetEntry *
|
||||
get_sortgroupclause_tle(SortClause *sortClause,
|
||||
List *targetList)
|
||||
{
|
||||
Index refnumber = sortClause->tleSortGroupRef;
|
||||
List *l;
|
||||
|
||||
foreach(l, targetList)
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(l);
|
||||
|
||||
if (tle->resdom->ressortgroupref == refnumber)
|
||||
return tle;
|
||||
}
|
||||
|
||||
elog(ERROR, "get_sortgroupclause_tle: ORDER/GROUP BY expression not found in targetlist");
|
||||
return NULL; /* keep compiler quiet */
|
||||
}
|
||||
|
||||
/*
|
||||
* get_sortgroupclause_expr
|
||||
* Find the targetlist entry matching the given SortClause
|
||||
@@ -227,17 +254,7 @@ get_expr(TargetEntry *tle)
|
||||
Node *
|
||||
get_sortgroupclause_expr(SortClause *sortClause, List *targetList)
|
||||
{
|
||||
Index refnumber = sortClause->tleSortGroupRef;
|
||||
List *l;
|
||||
TargetEntry *tle = get_sortgroupclause_tle(sortClause, targetList);
|
||||
|
||||
foreach(l, targetList)
|
||||
{
|
||||
TargetEntry *tle = (TargetEntry *) lfirst(l);
|
||||
|
||||
if (tle->resdom->ressortgroupref == refnumber)
|
||||
return tle->expr;
|
||||
}
|
||||
|
||||
elog(ERROR, "get_sortgroupclause_expr: ORDER/GROUP BY expression not found in targetlist");
|
||||
return NULL; /* keep compiler quiet */
|
||||
return tle->expr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user