From dd979f66be20fc54aad06da743f788fbc505bbe1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 27 Jan 2000 18:11:50 +0000 Subject: 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... --- src/backend/parser/analyze.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/backend/parser/analyze.c') diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 48178bcb21..fd3dda8f17 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: analyze.c,v 1.133 2000/01/26 05:56:41 momjian Exp $ + * $Id: analyze.c,v 1.134 2000/01/27 18:11:35 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -247,7 +247,7 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt) makeRangeTable(pstate, NULL, NULL); setTargetTable(pstate, stmt->relname); - qry->uniqueFlag = NULL; + qry->distinctClause = NIL; /* fix where clause */ qry->qual = transformWhereClause(pstate, stmt->whereClause, NULL); @@ -296,8 +296,6 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) /* set up a range table --- note INSERT target is not in it yet */ makeRangeTable(pstate, stmt->fromClause, &fromQual); - qry->uniqueFlag = stmt->unique; - qry->targetList = transformTargetList(pstate, stmt->targetList); qry->qual = transformWhereClause(pstate, stmt->whereClause, fromQual); @@ -311,13 +309,13 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) stmt->groupClause, qry->targetList); - /* An InsertStmt has no sortClause, but we still call - * transformSortClause because it also handles uniqueFlag. - */ - qry->sortClause = transformSortClause(pstate, - NIL, - qry->targetList, - qry->uniqueFlag); + /* An InsertStmt has no sortClause */ + qry->sortClause = NIL; + + qry->distinctClause = transformDistinctClause(pstate, + stmt->distinctClause, + qry->targetList, + & qry->sortClause); qry->hasSubLinks = pstate->p_hasSubLinks; qry->hasAggs = pstate->p_hasAggs; @@ -1312,8 +1310,6 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) /* set up a range table */ makeRangeTable(pstate, stmt->fromClause, &fromQual); - qry->uniqueFlag = stmt->unique; - qry->into = stmt->into; qry->isTemp = stmt->istemp; qry->isPortal = FALSE; @@ -1333,8 +1329,12 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt) qry->sortClause = transformSortClause(pstate, stmt->sortClause, - qry->targetList, - qry->uniqueFlag); + qry->targetList); + + qry->distinctClause = transformDistinctClause(pstate, + stmt->distinctClause, + qry->targetList, + & qry->sortClause); qry->hasSubLinks = pstate->p_hasSubLinks; qry->hasAggs = pstate->p_hasAggs; @@ -1558,9 +1558,9 @@ CheckSelectForUpdate(Query *qry) { if (qry->unionClause != NULL) elog(ERROR, "SELECT FOR UPDATE is not allowed with UNION/INTERSECT/EXCEPT clause"); - if (qry->uniqueFlag != NULL) + if (qry->distinctClause != NIL) elog(ERROR, "SELECT FOR UPDATE is not allowed with DISTINCT clause"); - if (qry->groupClause != NULL) + if (qry->groupClause != NIL) elog(ERROR, "SELECT FOR UPDATE is not allowed with GROUP BY clause"); if (qry->hasAggs) elog(ERROR, "SELECT FOR UPDATE is not allowed with AGGREGATE"); -- cgit v1.2.1