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

3654{
3655 Assert(WindowObjectIsValid(winobj));
3657 {
3658 const char *funcname = get_func_name(fcinfo->flinfo->fn_oid);
3659
3660 if (!funcname)
3661 elog(ERROR, "could not get function name");
3662 ereport(ERROR,
3664 errmsg("function %s does not allow RESPECT/IGNORE NULLS",
3665 funcname)));
3666 }
3667 else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS)
3668 winobj->ignore_nulls = IGNORE_NULLS;
3669}
#define Assert(condition)
Definition c.h:943
int errcode(int sqlerrcode)
Definition elog.c:875
#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:1839
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 4196 of file nodeWindowAgg.c.

4197{
4198 WindowAggState *winstate;
4199 ExprContext *econtext;
4200
4201 Assert(WindowObjectIsValid(winobj));
4202 winstate = winobj->winstate;
4203
4204 econtext = winstate->ss.ps.ps_ExprContext;
4205
4206 econtext->ecxt_outertuple = winstate->ss.ss_ScanTupleSlot;
4207 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4208 econtext, isnull);
4209}
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 3997 of file nodeWindowAgg.c.

4000{
4001 WindowAggState *winstate;
4002 ExprContext *econtext;
4003 TupleTableSlot *slot;
4004 int64 abs_pos;
4006
4007 Assert(WindowObjectIsValid(winobj));
4008 winstate = winobj->winstate;
4009 econtext = winstate->ss.ps.ps_ExprContext;
4010 slot = winstate->temp_slot_1;
4011
4012 if (winobj->ignore_nulls == IGNORE_NULLS)
4014 set_mark, isnull, isout);
4015
4016 switch (seektype)
4017 {
4019 elog(ERROR, "WINDOW_SEEK_CURRENT is not supported for WinGetFuncArgInFrame");
4020 abs_pos = mark_pos = 0; /* keep compiler quiet */
4021 break;
4022 case WINDOW_SEEK_HEAD:
4023 /* rejecting relpos < 0 is easy and simplifies code below */
4024 if (relpos < 0)
4025 goto out_of_frame;
4026 update_frameheadpos(winstate);
4027 abs_pos = winstate->frameheadpos + relpos;
4028 mark_pos = abs_pos;
4029
4030 /*
4031 * Account for exclusion option if one is active, but advance only
4032 * abs_pos not mark_pos. This prevents changes of the current
4033 * row's peer group from resulting in trying to fetch a row before
4034 * some previous mark position.
4035 *
4036 * Note that in some corner cases such as current row being
4037 * outside frame, these calculations are theoretically too simple,
4038 * but it doesn't matter because we'll end up deciding the row is
4039 * out of frame. We do not attempt to avoid fetching rows past
4040 * end of frame; that would happen in some cases anyway.
4041 */
4042 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
4043 {
4044 case 0:
4045 /* no adjustment needed */
4046 break;
4048 if (abs_pos >= winstate->currentpos &&
4049 winstate->currentpos >= winstate->frameheadpos)
4050 abs_pos++;
4051 break;
4053 update_grouptailpos(winstate);
4054 if (abs_pos >= winstate->groupheadpos &&
4055 winstate->grouptailpos > winstate->frameheadpos)
4056 {
4057 int64 overlapstart = Max(winstate->groupheadpos,
4058 winstate->frameheadpos);
4059
4060 abs_pos += winstate->grouptailpos - overlapstart;
4061 }
4062 break;
4064 update_grouptailpos(winstate);
4065 if (abs_pos >= winstate->groupheadpos &&
4066 winstate->grouptailpos > winstate->frameheadpos)
4067 {
4068 int64 overlapstart = Max(winstate->groupheadpos,
4069 winstate->frameheadpos);
4070
4071 if (abs_pos == overlapstart)
4072 abs_pos = winstate->currentpos;
4073 else
4074 abs_pos += winstate->grouptailpos - overlapstart - 1;
4075 }
4076 break;
4077 default:
4078 elog(ERROR, "unrecognized frame option state: 0x%x",
4079 winstate->frameOptions);
4080 break;
4081 }
4082 break;
4083 case WINDOW_SEEK_TAIL:
4084 /* rejecting relpos > 0 is easy and simplifies code below */
4085 if (relpos > 0)
4086 goto out_of_frame;
4087 update_frametailpos(winstate);
4088 abs_pos = winstate->frametailpos - 1 + relpos;
4089
4090 /*
4091 * Account for exclusion option if one is active. If there is no
4092 * exclusion, we can safely set the mark at the accessed row. But
4093 * if there is, we can only mark the frame start, because we can't
4094 * be sure how far back in the frame the exclusion might cause us
4095 * to fetch in future. Furthermore, we have to actually check
4096 * against frameheadpos here, since it's unsafe to try to fetch a
4097 * row before frame start if the mark might be there already.
4098 */
4099 switch (winstate->frameOptions & FRAMEOPTION_EXCLUSION)
4100 {
4101 case 0:
4102 /* no adjustment needed */
4103 mark_pos = abs_pos;
4104 break;
4106 if (abs_pos <= winstate->currentpos &&
4107 winstate->currentpos < winstate->frametailpos)
4108 abs_pos--;
4109 update_frameheadpos(winstate);
4110 if (abs_pos < winstate->frameheadpos)
4111 goto out_of_frame;
4112 mark_pos = winstate->frameheadpos;
4113 break;
4115 update_grouptailpos(winstate);
4116 if (abs_pos < winstate->grouptailpos &&
4117 winstate->groupheadpos < winstate->frametailpos)
4118 {
4119 int64 overlapend = Min(winstate->grouptailpos,
4120 winstate->frametailpos);
4121
4122 abs_pos -= overlapend - winstate->groupheadpos;
4123 }
4124 update_frameheadpos(winstate);
4125 if (abs_pos < winstate->frameheadpos)
4126 goto out_of_frame;
4127 mark_pos = winstate->frameheadpos;
4128 break;
4130 update_grouptailpos(winstate);
4131 if (abs_pos < winstate->grouptailpos &&
4132 winstate->groupheadpos < winstate->frametailpos)
4133 {
4134 int64 overlapend = Min(winstate->grouptailpos,
4135 winstate->frametailpos);
4136
4137 if (abs_pos == overlapend - 1)
4138 abs_pos = winstate->currentpos;
4139 else
4140 abs_pos -= overlapend - 1 - winstate->groupheadpos;
4141 }
4142 update_frameheadpos(winstate);
4143 if (abs_pos < winstate->frameheadpos)
4144 goto out_of_frame;
4145 mark_pos = winstate->frameheadpos;
4146 break;
4147 default:
4148 elog(ERROR, "unrecognized frame option state: 0x%x",
4149 winstate->frameOptions);
4150 mark_pos = 0; /* keep compiler quiet */
4151 break;
4152 }
4153 break;
4154 default:
4155 elog(ERROR, "unrecognized window seek type: %d", seektype);
4156 abs_pos = mark_pos = 0; /* keep compiler quiet */
4157 break;
4158 }
4159
4160 if (!window_gettupleslot(winobj, abs_pos, slot))
4161 goto out_of_frame;
4162
4163 /* The code above does not detect all out-of-frame cases, so check */
4164 if (row_is_in_frame(winobj, abs_pos, slot, false) <= 0)
4165 goto out_of_frame;
4166
4167 if (isout)
4168 *isout = false;
4169 if (set_mark)
4171 econtext->ecxt_outertuple = slot;
4172 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4173 econtext, isnull);
4174
4176 if (isout)
4177 *isout = true;
4178 *isnull = true;
4179 return (Datum) 0;
4180}
#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 3824 of file nodeWindowAgg.c.

3827{
3828 WindowAggState *winstate;
3829 int64 abs_pos;
3831 Datum datum;
3832 bool null_treatment;
3833 int notnull_offset;
3834 int notnull_relpos;
3835 int forward;
3836 bool myisout;
3837 bool got_datum;
3838
3839 Assert(WindowObjectIsValid(winobj));
3840 winstate = winobj->winstate;
3841
3842 null_treatment = (winobj->ignore_nulls == IGNORE_NULLS && relpos != 0);
3843
3844 switch (seektype)
3845 {
3847 if (null_treatment)
3848 abs_pos = winstate->currentpos;
3849 else
3850 abs_pos = winstate->currentpos + relpos;
3851 break;
3852 case WINDOW_SEEK_HEAD:
3853 if (null_treatment)
3854 abs_pos = 0;
3855 else
3856 abs_pos = relpos;
3857 break;
3858 case WINDOW_SEEK_TAIL:
3859 spool_tuples(winstate, -1);
3860 abs_pos = winstate->spooled_rows - 1 + relpos;
3861 break;
3862 default:
3863 elog(ERROR, "unrecognized window seek type: %d", seektype);
3864 abs_pos = 0; /* keep compiler quiet */
3865 break;
3866 }
3867
3868 /* Easy case if IGNORE NULLS is not specified */
3869 if (!null_treatment)
3870 {
3871 /* get tuple and evaluate in partition */
3872 datum = gettuple_eval_partition(winobj, argno,
3873 abs_pos, isnull, &myisout);
3874 if (!myisout && set_mark)
3875 WinSetMarkPosition(winobj, abs_pos);
3876 if (isout)
3877 *isout = myisout;
3878 return datum;
3879 }
3880
3881 /* Prepare for loop */
3882 notnull_offset = 0;
3884 forward = relpos > 0 ? 1 : -1;
3885 myisout = false;
3886 got_datum = false;
3887 datum = 0;
3888
3889 /*
3890 * IGNORE NULLS + WINDOW_SEEK_CURRENT + relpos > 0 case, we would fetch
3891 * beyond the current row + relpos to find out the target row. If we mark
3892 * at abs_pos, next call to WinGetFuncArgInPartition or
3893 * WinGetFuncArgInFrame (in case when a window function have multiple
3894 * args) could fail with "cannot fetch row before WindowObject's mark
3895 * position". So keep the mark position at currentpos.
3896 */
3897 if (seektype == WINDOW_SEEK_CURRENT && relpos > 0)
3898 mark_pos = winstate->currentpos;
3899 else
3900 {
3901 /*
3902 * For other cases we have no idea what position of row callers would
3903 * fetch next time. Also for relpos < 0 case (we go backward), we
3904 * cannot set mark either. For those cases we always set mark at 0.
3905 */
3906 mark_pos = 0;
3907 }
3908
3909 /*
3910 * Get the next nonnull value in the partition, moving forward or backward
3911 * until we find a value or reach the partition's end. We cache the
3912 * nullness status because we may repeat this process many times.
3913 */
3914 do
3915 {
3916 int nn_info; /* NOT NULL status */
3917
3918 abs_pos += forward;
3919 if (abs_pos < 0) /* clearly out of partition */
3920 break;
3921
3922 /* check NOT NULL cached info */
3924 if (nn_info == NN_NOTNULL) /* this row is known to be NOT NULL */
3926 else if (nn_info == NN_NULL) /* this row is known to be NULL */
3927 continue; /* keep on moving forward or backward */
3928 else /* need to check NULL or not */
3929 {
3930 /*
3931 * NOT NULL info does not exist yet. Get tuple and evaluate func
3932 * arg in partition. Keep the return value in case this row is the
3933 * target; re-evaluating a volatile argument could give a
3934 * different nullness status.
3935 */
3936 datum = gettuple_eval_partition(winobj, argno,
3937 abs_pos, isnull, &myisout);
3938 if (myisout) /* out of partition? */
3939 break;
3940 if (!*isnull)
3941 {
3944 got_datum = true;
3945 }
3946 /* record the row status */
3947 put_notnull_info(winobj, abs_pos, argno, *isnull);
3948 }
3949 } while (notnull_offset < notnull_relpos);
3950
3951 /* get tuple and evaluate func arg in partition */
3952 if (!got_datum)
3953 datum = gettuple_eval_partition(winobj, argno,
3954 abs_pos, isnull, &myisout);
3955 if (!myisout && set_mark)
3957 if (isout)
3958 *isout = myisout;
3959
3960 return datum;
3961}
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 3684 of file nodeWindowAgg.c.

3685{
3686 Assert(WindowObjectIsValid(winobj));
3687 if (winobj->localmem == NULL)
3688 winobj->localmem =
3690 return winobj->localmem;
3691}
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition mcxt.c:1269
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 3714 of file nodeWindowAgg.c.

3715{
3716 Assert(WindowObjectIsValid(winobj));
3717 spool_tuples(winobj->winstate, -1);
3718 return winobj->winstate->spooled_rows;
3719}

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

3768{
3769 WindowAggState *winstate;
3770 WindowAgg *node;
3773 bool res;
3774
3775 Assert(WindowObjectIsValid(winobj));
3776 winstate = winobj->winstate;
3777 node = (WindowAgg *) winstate->ss.ps.plan;
3778
3779 /* If no ORDER BY, all rows are peers; don't bother to fetch them */
3780 if (node->ordNumCols == 0)
3781 return true;
3782
3783 /*
3784 * Note: OK to use temp_slot_2 here because we aren't calling any
3785 * frame-related functions (those tend to clobber temp_slot_2).
3786 */
3787 slot1 = winstate->temp_slot_1;
3788 slot2 = winstate->temp_slot_2;
3789
3790 if (!window_gettupleslot(winobj, pos1, slot1))
3791 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3792 pos1);
3793 if (!window_gettupleslot(winobj, pos2, slot2))
3794 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3795 pos2);
3796
3797 res = are_peers(winstate, slot1, slot2);
3798
3801
3802 return res;
3803}
#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 3732 of file nodeWindowAgg.c.

3733{
3734 WindowAggState *winstate;
3735
3736 Assert(WindowObjectIsValid(winobj));
3737 winstate = winobj->winstate;
3738
3739 if (markpos < winobj->markpos)
3740 elog(ERROR, "cannot move WindowObject's mark position backward");
3741 tuplestore_select_read_pointer(winstate->buffer, winobj->markptr);
3742 if (markpos > winobj->markpos)
3743 {
3744 tuplestore_skiptuples(winstate->buffer,
3745 markpos - winobj->markpos,
3746 true);
3747 winobj->markpos = markpos;
3748 }
3749 tuplestore_select_read_pointer(winstate->buffer, winobj->readptr);
3750 if (markpos > winobj->seekpos)
3751 {
3752 tuplestore_skiptuples(winstate->buffer,
3753 markpos - winobj->seekpos,
3754 true);
3755 winobj->seekpos = markpos;
3756 }
3757}
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().