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 3580 of file nodeWindowAgg.c.

3583{
3584 Assert(WindowObjectIsValid(winobj));
3586 {
3587 const char *funcname = get_func_name(fcinfo->flinfo->fn_oid);
3588
3589 if (!funcname)
3590 elog(ERROR, "could not get function name");
3591 ereport(ERROR,
3593 errmsg("function %s does not allow RESPECT/IGNORE NULLS",
3594 funcname)));
3595 }
3596 else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS)
3597 winobj->ignore_nulls = IGNORE_NULLS;
3598}
#define Assert(condition)
Definition c.h:945
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define ereport(elevel,...)
Definition elog.h:150
#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 4119 of file nodeWindowAgg.c.

4120{
4121 WindowAggState *winstate;
4122 ExprContext *econtext;
4123
4124 Assert(WindowObjectIsValid(winobj));
4125 winstate = winobj->winstate;
4126
4127 econtext = winstate->ss.ps.ps_ExprContext;
4128
4129 econtext->ecxt_outertuple = winstate->ss.ss_ScanTupleSlot;
4130 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4131 econtext, isnull);
4132}
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition executor.h:396
static void * list_nth(const List *list, int n)
Definition pg_list.h:299
TupleTableSlot * ecxt_outertuple
Definition execnodes.h:288
ExprContext * ps_ExprContext
Definition execnodes.h:1216
TupleTableSlot * ss_ScanTupleSlot
Definition execnodes.h:1636
PlanState ps
Definition execnodes.h:1633
ScanState ss
Definition execnodes.h:2501

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 3920 of file nodeWindowAgg.c.

3923{
3924 WindowAggState *winstate;
3925 ExprContext *econtext;
3926 TupleTableSlot *slot;
3927 int64 abs_pos;
3929
3930 Assert(WindowObjectIsValid(winobj));
3931 winstate = winobj->winstate;
3932 econtext = winstate->ss.ps.ps_ExprContext;
3933 slot = winstate->temp_slot_1;
3934
3935 if (winobj->ignore_nulls == IGNORE_NULLS)
3937 set_mark, isnull, isout);
3938
3939 switch (seektype)
3940 {
3942 elog(ERROR, "WINDOW_SEEK_CURRENT is not supported for WinGetFuncArgInFrame");
3943 abs_pos = mark_pos = 0; /* keep compiler quiet */
3944 break;
3945 case WINDOW_SEEK_HEAD:
3946 /* rejecting relpos < 0 is easy and simplifies code below */
3947 if (relpos < 0)
3948 goto out_of_frame;
3949 update_frameheadpos(winstate);
3950 abs_pos = winstate->frameheadpos + relpos;
3951 mark_pos = abs_pos;
3952
3953 /*
3954 * Account for exclusion option if one is active, but advance only
3955 * abs_pos not mark_pos. This prevents changes of the current
3956 * row's peer group from resulting in trying to fetch a row before
3957 * some previous mark position.
3958 *
3959 * Note that in some corner cases such as current row being
3960 * outside frame, these calculations are theoretically too simple,
3961 * but it doesn't matter because we'll end up deciding the row is
3962 * out of frame. We do not attempt to avoid fetching rows past
3963 * end of frame; that would happen in some cases anyway.
3964 */
3965 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
3966 {
3967 case 0:
3968 /* no adjustment needed */
3969 break;
3971 if (abs_pos >= winstate->currentpos &&
3972 winstate->currentpos >= winstate->frameheadpos)
3973 abs_pos++;
3974 break;
3976 update_grouptailpos(winstate);
3977 if (abs_pos >= winstate->groupheadpos &&
3978 winstate->grouptailpos > winstate->frameheadpos)
3979 {
3980 int64 overlapstart = Max(winstate->groupheadpos,
3981 winstate->frameheadpos);
3982
3983 abs_pos += winstate->grouptailpos - overlapstart;
3984 }
3985 break;
3987 update_grouptailpos(winstate);
3988 if (abs_pos >= winstate->groupheadpos &&
3989 winstate->grouptailpos > winstate->frameheadpos)
3990 {
3991 int64 overlapstart = Max(winstate->groupheadpos,
3992 winstate->frameheadpos);
3993
3994 if (abs_pos == overlapstart)
3995 abs_pos = winstate->currentpos;
3996 else
3997 abs_pos += winstate->grouptailpos - overlapstart - 1;
3998 }
3999 break;
4000 default:
4001 elog(ERROR, "unrecognized frame option state: 0x%x",
4002 winstate->frameOptions);
4003 break;
4004 }
4005 break;
4006 case WINDOW_SEEK_TAIL:
4007 /* rejecting relpos > 0 is easy and simplifies code below */
4008 if (relpos > 0)
4009 goto out_of_frame;
4010 update_frametailpos(winstate);
4011 abs_pos = winstate->frametailpos - 1 + relpos;
4012
4013 /*
4014 * Account for exclusion option if one is active. If there is no
4015 * exclusion, we can safely set the mark at the accessed row. But
4016 * if there is, we can only mark the frame start, because we can't
4017 * be sure how far back in the frame the exclusion might cause us
4018 * to fetch in future. Furthermore, we have to actually check
4019 * against frameheadpos here, since it's unsafe to try to fetch a
4020 * row before frame start if the mark might be there already.
4021 */
4022 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
4023 {
4024 case 0:
4025 /* no adjustment needed */
4026 mark_pos = abs_pos;
4027 break;
4029 if (abs_pos <= winstate->currentpos &&
4030 winstate->currentpos < winstate->frametailpos)
4031 abs_pos--;
4032 update_frameheadpos(winstate);
4033 if (abs_pos < winstate->frameheadpos)
4034 goto out_of_frame;
4035 mark_pos = winstate->frameheadpos;
4036 break;
4038 update_grouptailpos(winstate);
4039 if (abs_pos < winstate->grouptailpos &&
4040 winstate->groupheadpos < winstate->frametailpos)
4041 {
4042 int64 overlapend = Min(winstate->grouptailpos,
4043 winstate->frametailpos);
4044
4045 abs_pos -= overlapend - winstate->groupheadpos;
4046 }
4047 update_frameheadpos(winstate);
4048 if (abs_pos < winstate->frameheadpos)
4049 goto out_of_frame;
4050 mark_pos = winstate->frameheadpos;
4051 break;
4053 update_grouptailpos(winstate);
4054 if (abs_pos < winstate->grouptailpos &&
4055 winstate->groupheadpos < winstate->frametailpos)
4056 {
4057 int64 overlapend = Min(winstate->grouptailpos,
4058 winstate->frametailpos);
4059
4060 if (abs_pos == overlapend - 1)
4061 abs_pos = winstate->currentpos;
4062 else
4063 abs_pos -= overlapend - 1 - winstate->groupheadpos;
4064 }
4065 update_frameheadpos(winstate);
4066 if (abs_pos < winstate->frameheadpos)
4067 goto out_of_frame;
4068 mark_pos = winstate->frameheadpos;
4069 break;
4070 default:
4071 elog(ERROR, "unrecognized frame option state: 0x%x",
4072 winstate->frameOptions);
4073 mark_pos = 0; /* keep compiler quiet */
4074 break;
4075 }
4076 break;
4077 default:
4078 elog(ERROR, "unrecognized window seek type: %d", seektype);
4079 abs_pos = mark_pos = 0; /* keep compiler quiet */
4080 break;
4081 }
4082
4083 if (!window_gettupleslot(winobj, abs_pos, slot))
4084 goto out_of_frame;
4085
4086 /* The code above does not detect all out-of-frame cases, so check */
4087 if (row_is_in_frame(winobj, abs_pos, slot, false) <= 0)
4088 goto out_of_frame;
4089
4090 if (isout)
4091 *isout = false;
4092 if (set_mark)
4094 econtext->ecxt_outertuple = slot;
4095 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4096 econtext, isnull);
4097
4099 if (isout)
4100 *isout = true;
4101 *isnull = true;
4102 return (Datum) 0;
4103}
#define Min(x, y)
Definition c.h:1093
#define Max(x, y)
Definition c.h:1087
int64_t int64
Definition c.h:615
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:624
#define FRAMEOPTION_EXCLUDE_TIES
Definition parsenodes.h:626
#define FRAMEOPTION_EXCLUDE_GROUP
Definition parsenodes.h:625
#define FRAMEOPTION_EXCLUSION
Definition parsenodes.h:632
uint64_t Datum
Definition postgres.h:70
TupleTableSlot * temp_slot_1
Definition execnodes.h:2583
#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 3753 of file nodeWindowAgg.c.

3756{
3757 WindowAggState *winstate;
3758 int64 abs_pos;
3760 Datum datum;
3761 bool null_treatment;
3762 int notnull_offset;
3763 int notnull_relpos;
3764 int forward;
3765 bool myisout;
3766
3767 Assert(WindowObjectIsValid(winobj));
3768 winstate = winobj->winstate;
3769
3770 null_treatment = (winobj->ignore_nulls == IGNORE_NULLS && relpos != 0);
3771
3772 switch (seektype)
3773 {
3775 if (null_treatment)
3776 abs_pos = winstate->currentpos;
3777 else
3778 abs_pos = winstate->currentpos + relpos;
3779 break;
3780 case WINDOW_SEEK_HEAD:
3781 if (null_treatment)
3782 abs_pos = 0;
3783 else
3784 abs_pos = relpos;
3785 break;
3786 case WINDOW_SEEK_TAIL:
3787 spool_tuples(winstate, -1);
3788 abs_pos = winstate->spooled_rows - 1 + relpos;
3789 break;
3790 default:
3791 elog(ERROR, "unrecognized window seek type: %d", seektype);
3792 abs_pos = 0; /* keep compiler quiet */
3793 break;
3794 }
3795
3796 /* Easy case if IGNORE NULLS is not specified */
3797 if (!null_treatment)
3798 {
3799 /* get tuple and evaluate in partition */
3800 datum = gettuple_eval_partition(winobj, argno,
3801 abs_pos, isnull, &myisout);
3802 if (!myisout && set_mark)
3803 WinSetMarkPosition(winobj, abs_pos);
3804 if (isout)
3805 *isout = myisout;
3806 return datum;
3807 }
3808
3809 /* Prepare for loop */
3810 notnull_offset = 0;
3812 forward = relpos > 0 ? 1 : -1;
3813 myisout = false;
3814 datum = 0;
3815
3816 /*
3817 * IGNORE NULLS + WINDOW_SEEK_CURRENT + relpos > 0 case, we would fetch
3818 * beyond the current row + relpos to find out the target row. If we mark
3819 * at abs_pos, next call to WinGetFuncArgInPartition or
3820 * WinGetFuncArgInFrame (in case when a window function have multiple
3821 * args) could fail with "cannot fetch row before WindowObject's mark
3822 * position". So keep the mark position at currentpos.
3823 */
3824 if (seektype == WINDOW_SEEK_CURRENT && relpos > 0)
3825 mark_pos = winstate->currentpos;
3826 else
3827 {
3828 /*
3829 * For other cases we have no idea what position of row callers would
3830 * fetch next time. Also for relpos < 0 case (we go backward), we
3831 * cannot set mark either. For those cases we always set mark at 0.
3832 */
3833 mark_pos = 0;
3834 }
3835
3836 /*
3837 * Get the next nonnull value in the partition, moving forward or backward
3838 * until we find a value or reach the partition's end. We cache the
3839 * nullness status because we may repeat this process many times.
3840 */
3841 do
3842 {
3843 int nn_info; /* NOT NULL status */
3844
3845 abs_pos += forward;
3846 if (abs_pos < 0) /* clearly out of partition */
3847 break;
3848
3849 /* check NOT NULL cached info */
3851 if (nn_info == NN_NOTNULL) /* this row is known to be NOT NULL */
3853 else if (nn_info == NN_NULL) /* this row is known to be NULL */
3854 continue; /* keep on moving forward or backward */
3855 else /* need to check NULL or not */
3856 {
3857 /*
3858 * NOT NULL info does not exist yet. Get tuple and evaluate func
3859 * arg in partition. We ignore the return value from
3860 * gettuple_eval_partition because we are just interested in
3861 * whether we are inside or outside of partition, NULL or NOT
3862 * NULL.
3863 */
3865 abs_pos, isnull, &myisout);
3866 if (myisout) /* out of partition? */
3867 break;
3868 if (!*isnull)
3870 /* record the row status */
3871 put_notnull_info(winobj, abs_pos, argno, *isnull);
3872 }
3873 } while (notnull_offset < notnull_relpos);
3874
3875 /* get tuple and evaluate func arg in partition */
3876 datum = gettuple_eval_partition(winobj, argno,
3877 abs_pos, isnull, &myisout);
3878 if (!myisout && set_mark)
3880 if (isout)
3881 *isout = myisout;
3882
3883 return datum;
3884}
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 3613 of file nodeWindowAgg.c.

3614{
3615 Assert(WindowObjectIsValid(winobj));
3616 if (winobj->localmem == NULL)
3617 winobj->localmem =
3619 return winobj->localmem;
3620}
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1266
MemoryContext partcontext
Definition execnodes.h:2558

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 3643 of file nodeWindowAgg.c.

3644{
3645 Assert(WindowObjectIsValid(winobj));
3646 spool_tuples(winobj->winstate, -1);
3647 return winobj->winstate->spooled_rows;
3648}

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 3696 of file nodeWindowAgg.c.

3697{
3698 WindowAggState *winstate;
3699 WindowAgg *node;
3702 bool res;
3703
3704 Assert(WindowObjectIsValid(winobj));
3705 winstate = winobj->winstate;
3706 node = (WindowAgg *) winstate->ss.ps.plan;
3707
3708 /* If no ORDER BY, all rows are peers; don't bother to fetch them */
3709 if (node->ordNumCols == 0)
3710 return true;
3711
3712 /*
3713 * Note: OK to use temp_slot_2 here because we aren't calling any
3714 * frame-related functions (those tend to clobber temp_slot_2).
3715 */
3716 slot1 = winstate->temp_slot_1;
3717 slot2 = winstate->temp_slot_2;
3718
3719 if (!window_gettupleslot(winobj, pos1, slot1))
3720 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3721 pos1);
3722 if (!window_gettupleslot(winobj, pos2, slot2))
3723 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3724 pos2);
3725
3726 res = are_peers(winstate, slot1, slot2);
3727
3730
3731 return res;
3732}
#define INT64_FORMAT
Definition c.h:636
static bool are_peers(WindowAggState *winstate, TupleTableSlot *slot1, TupleTableSlot *slot2)
Plan * plan
Definition execnodes.h:1177
TupleTableSlot * temp_slot_2
Definition execnodes.h:2584
int ordNumCols
Definition plannodes.h:1270
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 3661 of file nodeWindowAgg.c.

3662{
3663 WindowAggState *winstate;
3664
3665 Assert(WindowObjectIsValid(winobj));
3666 winstate = winobj->winstate;
3667
3668 if (markpos < winobj->markpos)
3669 elog(ERROR, "cannot move WindowObject's mark position backward");
3670 tuplestore_select_read_pointer(winstate->buffer, winobj->markptr);
3671 if (markpos > winobj->markpos)
3672 {
3673 tuplestore_skiptuples(winstate->buffer,
3674 markpos - winobj->markpos,
3675 true);
3676 winobj->markpos = markpos;
3677 }
3678 tuplestore_select_read_pointer(winstate->buffer, winobj->readptr);
3679 if (markpos > winobj->seekpos)
3680 {
3681 tuplestore_skiptuples(winstate->buffer,
3682 markpos - winobj->seekpos,
3683 true);
3684 winobj->seekpos = markpos;
3685 }
3686}
Tuplestorestate * buffer
Definition execnodes.h:2512
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().