1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-22 12:22:45 +03:00

Re-implement LIMIT/OFFSET as a plan node type, instead of a hack in

ExecutorRun.  This allows LIMIT to work in a view.  Also, LIMIT in a
cursor declaration will behave in a reasonable fashion, whereas before
it was overridden by the FETCH count.
This commit is contained in:
Tom Lane
2000-10-26 21:38:24 +00:00
parent c9476bafdb
commit 2f35b4efdb
26 changed files with 572 additions and 232 deletions

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: execnodes.h,v 1.51 2000/10/05 19:11:36 tgl Exp $
* $Id: execnodes.h,v 1.52 2000/10/26 21:38:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -675,6 +675,28 @@ typedef struct SetOpState
MemoryContext tempContext; /* short-term context for comparisons */
} SetOpState;
/* ----------------
* LimitState information
*
* Limit nodes are used to enforce LIMIT/OFFSET clauses.
* They just select the desired subrange of their subplan's output.
*
* offset is the number of initial tuples to skip (0 does nothing).
* count is the number of tuples to return after skipping the offset tuples.
* If no limit count was specified, count is undefined and noCount is true.
* ----------------
*/
typedef struct LimitState
{
CommonState cstate; /* its first field is NodeTag */
long offset; /* current OFFSET value */
long count; /* current COUNT, if any */
long position; /* 1-based index of last tuple fetched */
bool parmsSet; /* have we calculated offset/limit yet? */
bool noCount; /* if true, ignore count */
bool atEnd; /* if true, we've reached EOF of subplan */
} LimitState;
/* ----------------
* HashState information

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nodes.h,v 1.79 2000/10/22 23:32:44 tgl Exp $
* $Id: nodes.h,v 1.80 2000/10/26 21:38:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -39,7 +39,7 @@ typedef enum NodeTag
T_NestLoop,
T_MergeJoin,
T_HashJoin,
T_Noname_XXX, /* not used anymore; this tag# is available */
T_Limit,
T_Material,
T_Sort,
T_Agg,
@@ -122,6 +122,7 @@ typedef enum NodeTag
T_TidScanState,
T_SubqueryScanState,
T_SetOpState,
T_LimitState,
/*---------------------
* TAGS FOR MEMORY NODES (memnodes.h)

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: plannodes.h,v 1.44 2000/10/05 19:11:36 tgl Exp $
* $Id: plannodes.h,v 1.45 2000/10/26 21:38:12 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -47,6 +47,7 @@
* Sort SortState sortstate;
* Unique UniqueState uniquestate;
* SetOp SetOpState setopstate;
* Limit LimitState limitstate;
* Hash HashState hashstate;
*
* ----------------------------------------------------------------
@@ -375,6 +376,18 @@ typedef struct SetOp
SetOpState *setopstate;
} SetOp;
/* ----------------
* limit node
* ----------------
*/
typedef struct Limit
{
Plan plan;
Node *limitOffset; /* OFFSET parameter, or NULL if none */
Node *limitCount; /* COUNT parameter, or NULL if none */
LimitState *limitstate;
} Limit;
/* ----------------
* hash build node
* ----------------