33 * nodeUnique.c
44 * Routines to handle unique'ing of queries where appropriate
55 *
6+ * Unique is a very simple node type that just filters out duplicate
7+ * tuples from a stream of sorted tuples from its subplan. It's essentially
8+ * a dumbed-down form of Group: the duplicate-removal functionality is
9+ * identical. However, Unique doesn't do projection nor qual checking,
10+ * so it's marginally more efficient for cases where neither is needed.
11+ * (It's debatable whether the savings justifies carrying two plan node
12+ * types, though.)
13+ *
614 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
715 * Portions Copyright (c) 1994, Regents of the University of California
816 *
917 *
1018 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.56 2008/01/01 19:45:49 momjian Exp $
19+ * $PostgreSQL: pgsql/src/backend/executor/nodeUnique.c,v 1.57 2008/08/05 21:28:29 tgl Exp $
1220 *
1321 *-------------------------------------------------------------------------
1422 */
1523/*
1624 * INTERFACE ROUTINES
1725 *ExecUnique- generate a unique'd temporary relation
18- *ExecInitUnique- initialize node and subnodes..
26+ *ExecInitUnique- initialize node and subnodes
1927 *ExecEndUnique- shutdown node and subnodes
2028 *
2129 * NOTES
3240
3341/* ----------------------------------------------------------------
3442 *ExecUnique
35- *
36- *This is a very simple node which filters out duplicate
37- *tuples from a stream of sorted tuples from a subplan.
3843 * ----------------------------------------------------------------
3944 */
4045TupleTableSlot * /* return: a tuple or NULL */
@@ -54,11 +59,7 @@ ExecUnique(UniqueState *node)
5459/*
5560 * now loop, returning only non-duplicate tuples. We assume that the
5661 * tuples arrive in sorted order so we can detect duplicates easily.
57- *
58- * We return the first tuple from each group of duplicates (or the last
59- * tuple of each group, when moving backwards). At either end of the
60- * subplan, clear the result slot so that we correctly return the
61- * first/last tuple when reversing direction.
62+ * The first tuple of each group is returned.
6263 */
6364for (;;)
6465{
@@ -68,13 +69,13 @@ ExecUnique(UniqueState *node)
6869slot = ExecProcNode (outerPlan );
6970if (TupIsNull (slot ))
7071{
71- /* end of subplan; reset in case we change direction */
72+ /* end of subplan, so we're done */
7273ExecClearTuple (resultTupleSlot );
7374return NULL ;
7475}
7576
7677/*
77- * Always return the first/last tuple from the subplan.
78+ * Always return the first tuple from the subplan.
7879 */
7980if (TupIsNull (resultTupleSlot ))
8081break ;
@@ -113,7 +114,7 @@ ExecInitUnique(Unique *node, EState *estate, int eflags)
113114UniqueState * uniquestate ;
114115
115116/* check for unsupported flags */
116- Assert (!(eflags & EXEC_FLAG_MARK ));
117+ Assert (!(eflags & ( EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK ) ));
117118
118119/*
119120 * create state structure