PostgreSQL Source Code git master
Loading...
Searching...
No Matches
windowapi.h File Reference
#include "fmgr.h"
Include dependency graph for windowapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WINDOW_SEEK_CURRENT   0
 
#define WINDOW_SEEK_HEAD   1
 
#define WINDOW_SEEK_TAIL   2
 
#define PG_WINDOW_OBJECT()   ((WindowObject) fcinfo->context)
 
#define WindowObjectIsValid(winobj)    ((winobj) != NULL && IsA(winobj, WindowObjectData))
 

Typedefs

typedef struct WindowObjectDataWindowObject
 

Functions

void WinCheckAndInitializeNullTreatment (WindowObject winobj, bool allowNullTreatment, FunctionCallInfo fcinfo)
 
voidWinGetPartitionLocalMemory (WindowObject winobj, Size sz)
 
int64 WinGetCurrentPosition (WindowObject winobj)
 
int64 WinGetPartitionRowCount (WindowObject winobj)
 
void WinSetMarkPosition (WindowObject winobj, int64 markpos)
 
bool WinRowsArePeers (WindowObject winobj, int64 pos1, int64 pos2)
 
Datum WinGetFuncArgInPartition (WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool *isnull, bool *isout)
 
Datum WinGetFuncArgInFrame (WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool *isnull, bool *isout)
 
Datum WinGetFuncArgCurrent (WindowObject winobj, int argno, bool *isnull)
 

Macro Definition Documentation

◆ PG_WINDOW_OBJECT

#define PG_WINDOW_OBJECT ( )    ((WindowObject) fcinfo->context)

Definition at line 41 of file windowapi.h.

◆ WINDOW_SEEK_CURRENT

#define WINDOW_SEEK_CURRENT   0

Definition at line 34 of file windowapi.h.

◆ WINDOW_SEEK_HEAD

#define WINDOW_SEEK_HEAD   1

Definition at line 35 of file windowapi.h.

◆ WINDOW_SEEK_TAIL

#define WINDOW_SEEK_TAIL   2

Definition at line 36 of file windowapi.h.

◆ WindowObjectIsValid

#define WindowObjectIsValid (   winobj)     ((winobj) != NULL && IsA(winobj, WindowObjectData))

Definition at line 43 of file windowapi.h.

Typedef Documentation

◆ WindowObject

Definition at line 39 of file windowapi.h.

Function Documentation

◆ WinCheckAndInitializeNullTreatment()

void WinCheckAndInitializeNullTreatment ( WindowObject  winobj,
bool  allowNullTreatment,
FunctionCallInfo  fcinfo 
)
extern

Definition at line 3628 of file nodeWindowAgg.c.

3631{
3632 Assert(WindowObjectIsValid(winobj));
3634 {
3635 const char *funcname = get_func_name(fcinfo->flinfo->fn_oid);
3636
3637 if (!funcname)
3638 elog(ERROR, "could not get function name");
3639 ereport(ERROR,
3641 errmsg("function %s does not allow RESPECT/IGNORE NULLS",
3642 funcname)));
3643 }
3644 else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS)
3645 winobj->ignore_nulls = IGNORE_NULLS;
3646}
#define Assert(condition)
Definition c.h:943
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
#define funcname
char * get_func_name(Oid funcid)
Definition lsyscache.c:1828
static char * errmsg
static int fb(int x)
#define PARSER_IGNORE_NULLS
Definition primnodes.h:590
#define IGNORE_NULLS
Definition primnodes.h:592
#define NO_NULLTREATMENT
Definition primnodes.h:589
Oid fn_oid
Definition fmgr.h:59
FmgrInfo * flinfo
Definition fmgr.h:87
#define WindowObjectIsValid(winobj)
Definition windowapi.h:43

References Assert, elog, ereport, errcode(), errmsg, ERROR, fb(), FunctionCallInfoBaseData::flinfo, FmgrInfo::fn_oid, funcname, get_func_name(), WindowObjectData::ignore_nulls, IGNORE_NULLS, NO_NULLTREATMENT, PARSER_IGNORE_NULLS, and WindowObjectIsValid.

Referenced by leadlag_common(), window_cume_dist(), window_dense_rank(), window_first_value(), window_last_value(), window_nth_value(), window_ntile(), window_percent_rank(), window_rank(), and window_row_number().

◆ WinGetCurrentPosition()

int64 WinGetCurrentPosition ( WindowObject  winobj)
extern

◆ WinGetFuncArgCurrent()

Datum WinGetFuncArgCurrent ( WindowObject  winobj,
int  argno,
bool isnull 
)
extern

Definition at line 4167 of file nodeWindowAgg.c.

4168{
4169 WindowAggState *winstate;
4170 ExprContext *econtext;
4171
4172 Assert(WindowObjectIsValid(winobj));
4173 winstate = winobj->winstate;
4174
4175 econtext = winstate->ss.ps.ps_ExprContext;
4176
4177 econtext->ecxt_outertuple = winstate->ss.ss_ScanTupleSlot;
4178 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4179 econtext, isnull);
4180}
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition executor.h:403
static void * list_nth(const List *list, int n)
Definition pg_list.h:331
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:291
ExprContext * ps_ExprContext
Definition execnodes.h:1242
TupleTableSlot * ss_ScanTupleSlot
Definition execnodes.h:1662
PlanState ps
Definition execnodes.h:1659
ScanState ss
Definition execnodes.h:2529

References WindowObjectData::argstates, Assert, ExprContext::ecxt_outertuple, ExecEvalExpr(), fb(), list_nth(), ScanState::ps, PlanState::ps_ExprContext, WindowAggState::ss, ScanState::ss_ScanTupleSlot, WindowObjectIsValid, and WindowObjectData::winstate.

Referenced by leadlag_common(), window_nth_value(), and window_ntile().

◆ WinGetFuncArgInFrame()

Datum WinGetFuncArgInFrame ( WindowObject  winobj,
int  argno,
int  relpos,
int  seektype,
bool  set_mark,
bool isnull,
bool isout 
)
extern

Definition at line 3968 of file nodeWindowAgg.c.

3971{
3972 WindowAggState *winstate;
3973 ExprContext *econtext;
3974 TupleTableSlot *slot;
3975 int64 abs_pos;
3977
3978 Assert(WindowObjectIsValid(winobj));
3979 winstate = winobj->winstate;
3980 econtext = winstate->ss.ps.ps_ExprContext;
3981 slot = winstate->temp_slot_1;
3982
3983 if (winobj->ignore_nulls == IGNORE_NULLS)
3985 set_mark, isnull, isout);
3986
3987 switch (seektype)
3988 {
3990 elog(ERROR, "WINDOW_SEEK_CURRENT is not supported for WinGetFuncArgInFrame");
3991 abs_pos = mark_pos = 0; /* keep compiler quiet */
3992 break;
3993 case WINDOW_SEEK_HEAD:
3994 /* rejecting relpos < 0 is easy and simplifies code below */
3995 if (relpos < 0)
3996 goto out_of_frame;
3997 update_frameheadpos(winstate);
3998 abs_pos = winstate->frameheadpos + relpos;
3999 mark_pos = abs_pos;
4000
4001 /*
4002 * Account for exclusion option if one is active, but advance only
4003 * abs_pos not mark_pos. This prevents changes of the current
4004 * row's peer group from resulting in trying to fetch a row before
4005 * some previous mark position.
4006 *
4007 * Note that in some corner cases such as current row being
4008 * outside frame, these calculations are theoretically too simple,
4009 * but it doesn't matter because we'll end up deciding the row is
4010 * out of frame. We do not attempt to avoid fetching rows past
4011 * end of frame; that would happen in some cases anyway.
4012 */
4013 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
4014 {
4015 case 0:
4016 /* no adjustment needed */
4017 break;
4019 if (abs_pos >= winstate->currentpos &&
4020 winstate->currentpos >= winstate->frameheadpos)
4021 abs_pos++;
4022 break;
4024 update_grouptailpos(winstate);
4025 if (abs_pos >= winstate->groupheadpos &&
4026 winstate->grouptailpos > winstate->frameheadpos)
4027 {
4028 int64 overlapstart = Max(winstate->groupheadpos,
4029 winstate->frameheadpos);
4030
4031 abs_pos += winstate->grouptailpos - overlapstart;
4032 }
4033 break;
4035 update_grouptailpos(winstate);
4036 if (abs_pos >= winstate->groupheadpos &&
4037 winstate->grouptailpos > winstate->frameheadpos)
4038 {
4039 int64 overlapstart = Max(winstate->groupheadpos,
4040 winstate->frameheadpos);
4041
4042 if (abs_pos == overlapstart)
4043 abs_pos = winstate->currentpos;
4044 else
4045 abs_pos += winstate->grouptailpos - overlapstart - 1;
4046 }
4047 break;
4048 default:
4049 elog(ERROR, "unrecognized frame option state: 0x%x",
4050 winstate->frameOptions);
4051 break;
4052 }
4053 break;
4054 case WINDOW_SEEK_TAIL:
4055 /* rejecting relpos > 0 is easy and simplifies code below */
4056 if (relpos > 0)
4057 goto out_of_frame;
4058 update_frametailpos(winstate);
4059 abs_pos = winstate->frametailpos - 1 + relpos;
4060
4061 /*
4062 * Account for exclusion option if one is active. If there is no
4063 * exclusion, we can safely set the mark at the accessed row. But
4064 * if there is, we can only mark the frame start, because we can't
4065 * be sure how far back in the frame the exclusion might cause us
4066 * to fetch in future. Furthermore, we have to actually check
4067 * against frameheadpos here, since it's unsafe to try to fetch a
4068 * row before frame start if the mark might be there already.
4069 */
4070 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
4071 {
4072 case 0:
4073 /* no adjustment needed */
4074 mark_pos = abs_pos;
4075 break;
4077 if (abs_pos <= winstate->currentpos &&
4078 winstate->currentpos < winstate->frametailpos)
4079 abs_pos--;
4080 update_frameheadpos(winstate);
4081 if (abs_pos < winstate->frameheadpos)
4082 goto out_of_frame;
4083 mark_pos = winstate->frameheadpos;
4084 break;
4086 update_grouptailpos(winstate);
4087 if (abs_pos < winstate->grouptailpos &&
4088 winstate->groupheadpos < winstate->frametailpos)
4089 {
4090 int64 overlapend = Min(winstate->grouptailpos,
4091 winstate->frametailpos);
4092
4093 abs_pos -= overlapend - winstate->groupheadpos;
4094 }
4095 update_frameheadpos(winstate);
4096 if (abs_pos < winstate->frameheadpos)
4097 goto out_of_frame;
4098 mark_pos = winstate->frameheadpos;
4099 break;
4101 update_grouptailpos(winstate);
4102 if (abs_pos < winstate->grouptailpos &&
4103 winstate->groupheadpos < winstate->frametailpos)
4104 {
4105 int64 overlapend = Min(winstate->grouptailpos,
4106 winstate->frametailpos);
4107
4108 if (abs_pos == overlapend - 1)
4109 abs_pos = winstate->currentpos;
4110 else
4111 abs_pos -= overlapend - 1 - winstate->groupheadpos;
4112 }
4113 update_frameheadpos(winstate);
4114 if (abs_pos < winstate->frameheadpos)
4115 goto out_of_frame;
4116 mark_pos = winstate->frameheadpos;
4117 break;
4118 default:
4119 elog(ERROR, "unrecognized frame option state: 0x%x",
4120 winstate->frameOptions);
4121 mark_pos = 0; /* keep compiler quiet */
4122 break;
4123 }
4124 break;
4125 default:
4126 elog(ERROR, "unrecognized window seek type: %d", seektype);
4127 abs_pos = mark_pos = 0; /* keep compiler quiet */
4128 break;
4129 }
4130
4131 if (!window_gettupleslot(winobj, abs_pos, slot))
4132 goto out_of_frame;
4133
4134 /* The code above does not detect all out-of-frame cases, so check */
4135 if (row_is_in_frame(winobj, abs_pos, slot, false) <= 0)
4136 goto out_of_frame;
4137
4138 if (isout)
4139 *isout = false;
4140 if (set_mark)
4142 econtext->ecxt_outertuple = slot;
4143 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4144 econtext, isnull);
4145
4147 if (isout)
4148 *isout = true;
4149 *isnull = true;
4150 return (Datum) 0;
4151}
#define Min(x, y)
Definition c.h:1091
#define Max(x, y)
Definition c.h:1085
int64_t int64
Definition c.h:621
static void update_grouptailpos(WindowAggState *winstate)
static Datum ignorenulls_getfuncarginframe(WindowObject winobj, int argno, int relpos, int seektype, bool set_mark, bool *isnull, bool *isout)
static bool window_gettupleslot(WindowObject winobj, int64 pos, TupleTableSlot *slot)
void WinSetMarkPosition(WindowObject winobj, int64 markpos)
static int row_is_in_frame(WindowObject winobj, int64 pos, TupleTableSlot *slot, bool fetch_tuple)
static void update_frametailpos(WindowAggState *winstate)
static void update_frameheadpos(WindowAggState *winstate)
#define FRAMEOPTION_EXCLUDE_CURRENT_ROW
Definition parsenodes.h:627
#define FRAMEOPTION_EXCLUDE_TIES
Definition parsenodes.h:629
#define FRAMEOPTION_EXCLUDE_GROUP
Definition parsenodes.h:628
#define FRAMEOPTION_EXCLUSION
Definition parsenodes.h:635
uint64_t Datum
Definition postgres.h:70
TupleTableSlot * temp_slot_1
Definition execnodes.h:2611
#define WINDOW_SEEK_TAIL
Definition windowapi.h:36
#define WINDOW_SEEK_HEAD
Definition windowapi.h:35
#define WINDOW_SEEK_CURRENT
Definition windowapi.h:34

References WindowObjectData::argstates, Assert, WindowAggState::currentpos, ExprContext::ecxt_outertuple, elog, ERROR, ExecEvalExpr(), fb(), WindowAggState::frameheadpos, FRAMEOPTION_EXCLUDE_CURRENT_ROW, FRAMEOPTION_EXCLUDE_GROUP, FRAMEOPTION_EXCLUDE_TIES, FRAMEOPTION_EXCLUSION, WindowAggState::frameOptions, WindowAggState::frametailpos, WindowAggState::groupheadpos, WindowAggState::grouptailpos, WindowObjectData::ignore_nulls, IGNORE_NULLS, ignorenulls_getfuncarginframe(), list_nth(), Max, Min, ScanState::ps, PlanState::ps_ExprContext, row_is_in_frame(), WindowAggState::ss, WindowAggState::temp_slot_1, update_frameheadpos(), update_frametailpos(), update_grouptailpos(), window_gettupleslot(), WINDOW_SEEK_CURRENT, WINDOW_SEEK_HEAD, WINDOW_SEEK_TAIL, WindowObjectIsValid, WinSetMarkPosition(), and WindowObjectData::winstate.

Referenced by window_first_value(), window_last_value(), and window_nth_value().

◆ WinGetFuncArgInPartition()

Datum WinGetFuncArgInPartition ( WindowObject  winobj,
int  argno,
int  relpos,
int  seektype,
bool  set_mark,
bool isnull,
bool isout 
)
extern

Definition at line 3801 of file nodeWindowAgg.c.

3804{
3805 WindowAggState *winstate;
3806 int64 abs_pos;
3808 Datum datum;
3809 bool null_treatment;
3810 int notnull_offset;
3811 int notnull_relpos;
3812 int forward;
3813 bool myisout;
3814
3815 Assert(WindowObjectIsValid(winobj));
3816 winstate = winobj->winstate;
3817
3818 null_treatment = (winobj->ignore_nulls == IGNORE_NULLS && relpos != 0);
3819
3820 switch (seektype)
3821 {
3823 if (null_treatment)
3824 abs_pos = winstate->currentpos;
3825 else
3826 abs_pos = winstate->currentpos + relpos;
3827 break;
3828 case WINDOW_SEEK_HEAD:
3829 if (null_treatment)
3830 abs_pos = 0;
3831 else
3832 abs_pos = relpos;
3833 break;
3834 case WINDOW_SEEK_TAIL:
3835 spool_tuples(winstate, -1);
3836 abs_pos = winstate->spooled_rows - 1 + relpos;
3837 break;
3838 default:
3839 elog(ERROR, "unrecognized window seek type: %d", seektype);
3840 abs_pos = 0; /* keep compiler quiet */
3841 break;
3842 }
3843
3844 /* Easy case if IGNORE NULLS is not specified */
3845 if (!null_treatment)
3846 {
3847 /* get tuple and evaluate in partition */
3848 datum = gettuple_eval_partition(winobj, argno,
3849 abs_pos, isnull, &myisout);
3850 if (!myisout && set_mark)
3851 WinSetMarkPosition(winobj, abs_pos);
3852 if (isout)
3853 *isout = myisout;
3854 return datum;
3855 }
3856
3857 /* Prepare for loop */
3858 notnull_offset = 0;
3860 forward = relpos > 0 ? 1 : -1;
3861 myisout = false;
3862 datum = 0;
3863
3864 /*
3865 * IGNORE NULLS + WINDOW_SEEK_CURRENT + relpos > 0 case, we would fetch
3866 * beyond the current row + relpos to find out the target row. If we mark
3867 * at abs_pos, next call to WinGetFuncArgInPartition or
3868 * WinGetFuncArgInFrame (in case when a window function have multiple
3869 * args) could fail with "cannot fetch row before WindowObject's mark
3870 * position". So keep the mark position at currentpos.
3871 */
3872 if (seektype == WINDOW_SEEK_CURRENT && relpos > 0)
3873 mark_pos = winstate->currentpos;
3874 else
3875 {
3876 /*
3877 * For other cases we have no idea what position of row callers would
3878 * fetch next time. Also for relpos < 0 case (we go backward), we
3879 * cannot set mark either. For those cases we always set mark at 0.
3880 */
3881 mark_pos = 0;
3882 }
3883
3884 /*
3885 * Get the next nonnull value in the partition, moving forward or backward
3886 * until we find a value or reach the partition's end. We cache the
3887 * nullness status because we may repeat this process many times.
3888 */
3889 do
3890 {
3891 int nn_info; /* NOT NULL status */
3892
3893 abs_pos += forward;
3894 if (abs_pos < 0) /* clearly out of partition */
3895 break;
3896
3897 /* check NOT NULL cached info */
3899 if (nn_info == NN_NOTNULL) /* this row is known to be NOT NULL */
3901 else if (nn_info == NN_NULL) /* this row is known to be NULL */
3902 continue; /* keep on moving forward or backward */
3903 else /* need to check NULL or not */
3904 {
3905 /*
3906 * NOT NULL info does not exist yet. Get tuple and evaluate func
3907 * arg in partition. We ignore the return value from
3908 * gettuple_eval_partition because we are just interested in
3909 * whether we are inside or outside of partition, NULL or NOT
3910 * NULL.
3911 */
3913 abs_pos, isnull, &myisout);
3914 if (myisout) /* out of partition? */
3915 break;
3916 if (!*isnull)
3918 /* record the row status */
3919 put_notnull_info(winobj, abs_pos, argno, *isnull);
3920 }
3921 } while (notnull_offset < notnull_relpos);
3922
3923 /* get tuple and evaluate func arg in partition */
3924 datum = gettuple_eval_partition(winobj, argno,
3925 abs_pos, isnull, &myisout);
3926 if (!myisout && set_mark)
3928 if (isout)
3929 *isout = myisout;
3930
3931 return datum;
3932}
static void spool_tuples(WindowAggState *winstate, int64 pos)
#define NN_NOTNULL
static void put_notnull_info(WindowObject winobj, int64 pos, int argno, bool isnull)
#define NN_NULL
static uint8 get_notnull_info(WindowObject winobj, int64 pos, int argno)
static Datum gettuple_eval_partition(WindowObject winobj, int argno, int64 abs_pos, bool *isnull, bool *isout)

References Assert, WindowAggState::currentpos, elog, ERROR, fb(), get_notnull_info(), gettuple_eval_partition(), WindowObjectData::ignore_nulls, IGNORE_NULLS, NN_NOTNULL, NN_NULL, put_notnull_info(), spool_tuples(), WindowAggState::spooled_rows, WINDOW_SEEK_CURRENT, WINDOW_SEEK_HEAD, WINDOW_SEEK_TAIL, WindowObjectIsValid, WinSetMarkPosition(), and WindowObjectData::winstate.

Referenced by leadlag_common().

◆ WinGetPartitionLocalMemory()

void * WinGetPartitionLocalMemory ( WindowObject  winobj,
Size  sz 
)
extern

Definition at line 3661 of file nodeWindowAgg.c.

3662{
3663 Assert(WindowObjectIsValid(winobj));
3664 if (winobj->localmem == NULL)
3665 winobj->localmem =
3667 return winobj->localmem;
3668}
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
MemoryContext partcontext
Definition execnodes.h:2586

References Assert, fb(), WindowObjectData::localmem, MemoryContextAllocZero(), WindowAggState::partcontext, WindowObjectIsValid, and WindowObjectData::winstate.

Referenced by rank_up(), window_cume_dist(), window_dense_rank(), window_ntile(), window_percent_rank(), and window_rank().

◆ WinGetPartitionRowCount()

int64 WinGetPartitionRowCount ( WindowObject  winobj)
extern

Definition at line 3691 of file nodeWindowAgg.c.

3692{
3693 Assert(WindowObjectIsValid(winobj));
3694 spool_tuples(winobj->winstate, -1);
3695 return winobj->winstate->spooled_rows;
3696}

References Assert, spool_tuples(), WindowAggState::spooled_rows, WindowObjectIsValid, and WindowObjectData::winstate.

Referenced by window_cume_dist(), window_ntile(), and window_percent_rank().

◆ WinRowsArePeers()

bool WinRowsArePeers ( WindowObject  winobj,
int64  pos1,
int64  pos2 
)
extern

Definition at line 3744 of file nodeWindowAgg.c.

3745{
3746 WindowAggState *winstate;
3747 WindowAgg *node;
3750 bool res;
3751
3752 Assert(WindowObjectIsValid(winobj));
3753 winstate = winobj->winstate;
3754 node = (WindowAgg *) winstate->ss.ps.plan;
3755
3756 /* If no ORDER BY, all rows are peers; don't bother to fetch them */
3757 if (node->ordNumCols == 0)
3758 return true;
3759
3760 /*
3761 * Note: OK to use temp_slot_2 here because we aren't calling any
3762 * frame-related functions (those tend to clobber temp_slot_2).
3763 */
3764 slot1 = winstate->temp_slot_1;
3765 slot2 = winstate->temp_slot_2;
3766
3767 if (!window_gettupleslot(winobj, pos1, slot1))
3768 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3769 pos1);
3770 if (!window_gettupleslot(winobj, pos2, slot2))
3771 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3772 pos2);
3773
3774 res = are_peers(winstate, slot1, slot2);
3775
3778
3779 return res;
3780}
#define INT64_FORMAT
Definition c.h:634
static bool are_peers(WindowAggState *winstate, TupleTableSlot *slot1, TupleTableSlot *slot2)
Plan * plan
Definition execnodes.h:1201
TupleTableSlot * temp_slot_2
Definition execnodes.h:2612
int ordNumCols
Definition plannodes.h:1274
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476

References are_peers(), Assert, elog, ERROR, ExecClearTuple(), fb(), INT64_FORMAT, WindowAgg::ordNumCols, PlanState::plan, ScanState::ps, WindowAggState::ss, WindowAggState::temp_slot_1, WindowAggState::temp_slot_2, window_gettupleslot(), WindowObjectIsValid, and WindowObjectData::winstate.

Referenced by rank_up(), and window_cume_dist().

◆ WinSetMarkPosition()

void WinSetMarkPosition ( WindowObject  winobj,
int64  markpos 
)
extern

Definition at line 3709 of file nodeWindowAgg.c.

3710{
3711 WindowAggState *winstate;
3712
3713 Assert(WindowObjectIsValid(winobj));
3714 winstate = winobj->winstate;
3715
3716 if (markpos < winobj->markpos)
3717 elog(ERROR, "cannot move WindowObject's mark position backward");
3718 tuplestore_select_read_pointer(winstate->buffer, winobj->markptr);
3719 if (markpos > winobj->markpos)
3720 {
3721 tuplestore_skiptuples(winstate->buffer,
3722 markpos - winobj->markpos,
3723 true);
3724 winobj->markpos = markpos;
3725 }
3726 tuplestore_select_read_pointer(winstate->buffer, winobj->readptr);
3727 if (markpos > winobj->seekpos)
3728 {
3729 tuplestore_skiptuples(winstate->buffer,
3730 markpos - winobj->seekpos,
3731 true);
3732 winobj->seekpos = markpos;
3733 }
3734}
Tuplestorestate * buffer
Definition execnodes.h:2540
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
Definition tuplestore.c:508
bool tuplestore_skiptuples(Tuplestorestate *state, int64 ntuples, bool forward)

References Assert, WindowAggState::buffer, elog, ERROR, fb(), WindowObjectData::markpos, WindowObjectData::markptr, WindowObjectData::readptr, WindowObjectData::seekpos, tuplestore_select_read_pointer(), tuplestore_skiptuples(), WindowObjectIsValid, and WindowObjectData::winstate.

Referenced by eval_windowaggregates(), ignorenulls_getfuncarginframe(), rank_up(), window_row_number(), WinGetFuncArgInFrame(), and WinGetFuncArgInPartition().