PostgreSQL Source Code git master
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)
 
void * WinGetPartitionLocalMemory (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

typedef struct WindowObjectData* WindowObject

Definition at line 39 of file windowapi.h.

Function Documentation

◆ WinCheckAndInitializeNullTreatment()

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

Definition at line 3578 of file nodeWindowAgg.c.

3581{
3582 Assert(WindowObjectIsValid(winobj));
3583 if (winobj->ignore_nulls != NO_NULLTREATMENT && !allowNullTreatment)
3584 {
3585 const char *funcname = get_func_name(fcinfo->flinfo->fn_oid);
3586
3587 if (!funcname)
3588 elog(ERROR, "could not get function name");
3589 ereport(ERROR,
3590 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3591 errmsg("function %s does not allow RESPECT/IGNORE NULLS",
3592 funcname)));
3593 }
3594 else if (winobj->ignore_nulls == PARSER_IGNORE_NULLS)
3595 winobj->ignore_nulls = IGNORE_NULLS;
3596}
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
Assert(PointerIsAligned(start, uint64))
#define funcname
Definition: indent_codes.h:69
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1775
#define PARSER_IGNORE_NULLS
Definition: primnodes.h:589
#define IGNORE_NULLS
Definition: primnodes.h:591
#define NO_NULLTREATMENT
Definition: primnodes.h:588
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, 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)

◆ WinGetFuncArgCurrent()

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

Definition at line 4117 of file nodeWindowAgg.c.

4118{
4119 WindowAggState *winstate;
4120 ExprContext *econtext;
4121
4122 Assert(WindowObjectIsValid(winobj));
4123 winstate = winobj->winstate;
4124
4125 econtext = winstate->ss.ps.ps_ExprContext;
4126
4127 econtext->ecxt_outertuple = winstate->ss.ss_ScanTupleSlot;
4128 return ExecEvalExpr((ExprState *) list_nth(winobj->argstates, argno),
4129 econtext, isnull);
4130}
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:393
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
TupleTableSlot * ecxt_outertuple
Definition: execnodes.h:277
ExprContext * ps_ExprContext
Definition: execnodes.h:1204
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1624
PlanState ps
Definition: execnodes.h:1621
ScanState ss
Definition: execnodes.h:2630

References WindowObjectData::argstates, Assert(), ExprContext::ecxt_outertuple, ExecEvalExpr(), 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 
)

Definition at line 3918 of file nodeWindowAgg.c.

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

Definition at line 3751 of file nodeWindowAgg.c.

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

References Assert(), WindowAggState::currentpos, elog, ERROR, 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 
)

Definition at line 3611 of file nodeWindowAgg.c.

3612{
3613 Assert(WindowObjectIsValid(winobj));
3614 if (winobj->localmem == NULL)
3615 winobj->localmem =
3617 return winobj->localmem;
3618}
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1263
MemoryContext partcontext
Definition: execnodes.h:2687

References Assert(), 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)

◆ WinRowsArePeers()

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

Definition at line 3694 of file nodeWindowAgg.c.

3695{
3696 WindowAggState *winstate;
3697 WindowAgg *node;
3698 TupleTableSlot *slot1;
3699 TupleTableSlot *slot2;
3700 bool res;
3701
3702 Assert(WindowObjectIsValid(winobj));
3703 winstate = winobj->winstate;
3704 node = (WindowAgg *) winstate->ss.ps.plan;
3705
3706 /* If no ORDER BY, all rows are peers; don't bother to fetch them */
3707 if (node->ordNumCols == 0)
3708 return true;
3709
3710 /*
3711 * Note: OK to use temp_slot_2 here because we aren't calling any
3712 * frame-related functions (those tend to clobber temp_slot_2).
3713 */
3714 slot1 = winstate->temp_slot_1;
3715 slot2 = winstate->temp_slot_2;
3716
3717 if (!window_gettupleslot(winobj, pos1, slot1))
3718 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3719 pos1);
3720 if (!window_gettupleslot(winobj, pos2, slot2))
3721 elog(ERROR, "specified position is out of window: " INT64_FORMAT,
3722 pos2);
3723
3724 res = are_peers(winstate, slot1, slot2);
3725
3726 ExecClearTuple(slot1);
3727 ExecClearTuple(slot2);
3728
3729 return res;
3730}
#define INT64_FORMAT
Definition: c.h:561
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
static bool are_peers(WindowAggState *winstate, TupleTableSlot *slot1, TupleTableSlot *slot2)
Plan * plan
Definition: execnodes.h:1165
TupleTableSlot * temp_slot_2
Definition: execnodes.h:2713
int ordNumCols
Definition: plannodes.h:1253
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:457

References are_peers(), Assert(), elog, ERROR, ExecClearTuple(), if(), 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 
)

Definition at line 3659 of file nodeWindowAgg.c.

3660{
3661 WindowAggState *winstate;
3662
3663 Assert(WindowObjectIsValid(winobj));
3664 winstate = winobj->winstate;
3665
3666 if (markpos < winobj->markpos)
3667 elog(ERROR, "cannot move WindowObject's mark position backward");
3668 tuplestore_select_read_pointer(winstate->buffer, winobj->markptr);
3669 if (markpos > winobj->markpos)
3670 {
3671 tuplestore_skiptuples(winstate->buffer,
3672 markpos - winobj->markpos,
3673 true);
3674 winobj->markpos = markpos;
3675 }
3676 tuplestore_select_read_pointer(winstate->buffer, winobj->readptr);
3677 if (markpos > winobj->seekpos)
3678 {
3679 tuplestore_skiptuples(winstate->buffer,
3680 markpos - winobj->seekpos,
3681 true);
3682 winobj->seekpos = markpos;
3683 }
3684}
Tuplestorestate * buffer
Definition: execnodes.h:2641
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
Definition: tuplestore.c:507
bool tuplestore_skiptuples(Tuplestorestate *state, int64 ntuples, bool forward)
Definition: tuplestore.c:1187

References Assert(), WindowAggState::buffer, elog, ERROR, 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().