mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
Extend the set of frame options supported for window functions.
This patch allows the frame to start from CURRENT ROW (in either RANGE or ROWS mode), and it also adds support for ROWS n PRECEDING and ROWS n FOLLOWING start and end points. (RANGE value PRECEDING/FOLLOWING isn't there yet --- the grammar works, but that's all.) Hitoshi Harada, reviewed by Pavel Stehule
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.460 2010/01/28 23:21:11 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.461 2010/02/12 17:33:20 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -718,6 +718,8 @@ _copyWindowAgg(WindowAgg *from)
|
||||
COPY_POINTER_FIELD(ordOperators, from->ordNumCols * sizeof(Oid));
|
||||
}
|
||||
COPY_SCALAR_FIELD(frameOptions);
|
||||
COPY_NODE_FIELD(startOffset);
|
||||
COPY_NODE_FIELD(endOffset);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
@ -1848,6 +1850,8 @@ _copyWindowClause(WindowClause *from)
|
||||
COPY_NODE_FIELD(partitionClause);
|
||||
COPY_NODE_FIELD(orderClause);
|
||||
COPY_SCALAR_FIELD(frameOptions);
|
||||
COPY_NODE_FIELD(startOffset);
|
||||
COPY_NODE_FIELD(endOffset);
|
||||
COPY_SCALAR_FIELD(winref);
|
||||
COPY_SCALAR_FIELD(copiedOrder);
|
||||
|
||||
@ -2076,6 +2080,8 @@ _copyWindowDef(WindowDef *from)
|
||||
COPY_NODE_FIELD(partitionClause);
|
||||
COPY_NODE_FIELD(orderClause);
|
||||
COPY_SCALAR_FIELD(frameOptions);
|
||||
COPY_NODE_FIELD(startOffset);
|
||||
COPY_NODE_FIELD(endOffset);
|
||||
COPY_LOCATION_FIELD(location);
|
||||
|
||||
return newnode;
|
||||
|
@ -22,7 +22,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.381 2010/01/28 23:21:11 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.382 2010/02/12 17:33:20 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -2056,6 +2056,8 @@ _equalWindowDef(WindowDef *a, WindowDef *b)
|
||||
COMPARE_NODE_FIELD(partitionClause);
|
||||
COMPARE_NODE_FIELD(orderClause);
|
||||
COMPARE_SCALAR_FIELD(frameOptions);
|
||||
COMPARE_NODE_FIELD(startOffset);
|
||||
COMPARE_NODE_FIELD(endOffset);
|
||||
COMPARE_LOCATION_FIELD(location);
|
||||
|
||||
return true;
|
||||
@ -2205,6 +2207,8 @@ _equalWindowClause(WindowClause *a, WindowClause *b)
|
||||
COMPARE_NODE_FIELD(partitionClause);
|
||||
COMPARE_NODE_FIELD(orderClause);
|
||||
COMPARE_SCALAR_FIELD(frameOptions);
|
||||
COMPARE_NODE_FIELD(startOffset);
|
||||
COMPARE_NODE_FIELD(endOffset);
|
||||
COMPARE_SCALAR_FIELD(winref);
|
||||
COMPARE_SCALAR_FIELD(copiedOrder);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.45 2010/01/02 16:57:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/nodeFuncs.c,v 1.46 2010/02/12 17:33:20 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1298,6 +1298,10 @@ expression_tree_walker(Node *node,
|
||||
return true;
|
||||
if (walker(wc->orderClause, context))
|
||||
return true;
|
||||
if (walker(wc->startOffset, context))
|
||||
return true;
|
||||
if (walker(wc->endOffset, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_CommonTableExpr:
|
||||
@ -1950,6 +1954,8 @@ expression_tree_mutator(Node *node,
|
||||
FLATCOPY(newnode, wc, WindowClause);
|
||||
MUTATE(newnode->partitionClause, wc->partitionClause, List *);
|
||||
MUTATE(newnode->orderClause, wc->orderClause, List *);
|
||||
MUTATE(newnode->startOffset, wc->startOffset, Node *);
|
||||
MUTATE(newnode->endOffset, wc->endOffset, Node *);
|
||||
return (Node *) newnode;
|
||||
}
|
||||
break;
|
||||
@ -2475,6 +2481,10 @@ bool
|
||||
return true;
|
||||
if (walker(wd->orderClause, context))
|
||||
return true;
|
||||
if (walker(wd->startOffset, context))
|
||||
return true;
|
||||
if (walker(wd->endOffset, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_RangeSubselect:
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.381 2010/01/28 23:21:12 petere Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.382 2010/02/12 17:33:20 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Every node type that can appear in stored rules' parsetrees *must*
|
||||
@ -610,6 +610,8 @@ _outWindowAgg(StringInfo str, WindowAgg *node)
|
||||
appendStringInfo(str, " %u", node->ordOperators[i]);
|
||||
|
||||
WRITE_INT_FIELD(frameOptions);
|
||||
WRITE_NODE_FIELD(startOffset);
|
||||
WRITE_NODE_FIELD(endOffset);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2035,6 +2037,8 @@ _outWindowClause(StringInfo str, WindowClause *node)
|
||||
WRITE_NODE_FIELD(partitionClause);
|
||||
WRITE_NODE_FIELD(orderClause);
|
||||
WRITE_INT_FIELD(frameOptions);
|
||||
WRITE_NODE_FIELD(startOffset);
|
||||
WRITE_NODE_FIELD(endOffset);
|
||||
WRITE_UINT_FIELD(winref);
|
||||
WRITE_BOOL_FIELD(copiedOrder);
|
||||
}
|
||||
@ -2326,6 +2330,8 @@ _outWindowDef(StringInfo str, WindowDef *node)
|
||||
WRITE_NODE_FIELD(partitionClause);
|
||||
WRITE_NODE_FIELD(orderClause);
|
||||
WRITE_INT_FIELD(frameOptions);
|
||||
WRITE_NODE_FIELD(startOffset);
|
||||
WRITE_NODE_FIELD(endOffset);
|
||||
WRITE_LOCATION_FIELD(location);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.230 2010/01/02 16:57:46 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.231 2010/02/12 17:33:20 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Path and Plan nodes do not have any readfuncs support, because we
|
||||
@ -279,6 +279,8 @@ _readWindowClause(void)
|
||||
READ_NODE_FIELD(partitionClause);
|
||||
READ_NODE_FIELD(orderClause);
|
||||
READ_INT_FIELD(frameOptions);
|
||||
READ_NODE_FIELD(startOffset);
|
||||
READ_NODE_FIELD(endOffset);
|
||||
READ_UINT_FIELD(winref);
|
||||
READ_BOOL_FIELD(copiedOrder);
|
||||
|
||||
|
Reference in New Issue
Block a user