PostgreSQL Source Code: src/include/windowapi.h File Reference (original) (raw)
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)) |
Functions | |
---|---|
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) |
◆ PG_WINDOW_OBJECT
#define PG_WINDOW_OBJECT | ( | ) | ((WindowObject) fcinfo->context) |
---|
◆ WINDOW_SEEK_CURRENT
#define WINDOW_SEEK_CURRENT 0
◆ WINDOW_SEEK_HEAD
#define WINDOW_SEEK_HEAD 1
◆ WINDOW_SEEK_TAIL
#define WINDOW_SEEK_TAIL 2
◆ WindowObjectIsValid
◆ WindowObject
◆ WinGetCurrentPosition()
◆ WinGetFuncArgCurrent()
Definition at line 3659 of file nodeWindowAgg.c.
3660{
3663
3665 winstate = winobj->winstate;
3666
3668
3671 econtext, isnull);
3672}
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
static void * list_nth(const List *list, int n)
TupleTableSlot * ecxt_outertuple
ExprContext * ps_ExprContext
TupleTableSlot * ss_ScanTupleSlot
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 3464 of file nodeWindowAgg.c.
3467{
3473
3475 winstate = winobj->winstate;
3478
3479 switch (seektype)
3480 {
3482 elog(ERROR, "WINDOW_SEEK_CURRENT is not supported for WinGetFuncArgInFrame");
3483 abs_pos = mark_pos = 0;
3484 break;
3486
3487 if (relpos < 0)
3488 goto out_of_frame;
3491 mark_pos = abs_pos;
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3506 {
3507 case 0:
3508
3509 break;
3511 if (abs_pos >= winstate->currentpos &&
3513 abs_pos++;
3514 break;
3519 {
3522
3523 abs_pos += winstate->grouptailpos - overlapstart;
3524 }
3525 break;
3530 {
3533
3534 if (abs_pos == overlapstart)
3536 else
3537 abs_pos += winstate->grouptailpos - overlapstart - 1;
3538 }
3539 break;
3540 default:
3541 elog(ERROR, "unrecognized frame option state: 0x%x",
3543 break;
3544 }
3545 break;
3547
3548 if (relpos > 0)
3549 goto out_of_frame;
3551 abs_pos = winstate->frametailpos - 1 + relpos;
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3563 {
3564 case 0:
3565
3566 mark_pos = abs_pos;
3567 break;
3569 if (abs_pos <= winstate->currentpos &&
3571 abs_pos--;
3573 if (abs_pos < winstate->frameheadpos)
3574 goto out_of_frame;
3576 break;
3579 if (abs_pos < winstate->grouptailpos &&
3581 {
3584
3585 abs_pos -= overlapend - winstate->groupheadpos;
3586 }
3588 if (abs_pos < winstate->frameheadpos)
3589 goto out_of_frame;
3591 break;
3594 if (abs_pos < winstate->grouptailpos &&
3596 {
3599
3600 if (abs_pos == overlapend - 1)
3602 else
3603 abs_pos -= overlapend - 1 - winstate->groupheadpos;
3604 }
3606 if (abs_pos < winstate->frameheadpos)
3607 goto out_of_frame;
3609 break;
3610 default:
3611 elog(ERROR, "unrecognized frame option state: 0x%x",
3613 mark_pos = 0;
3614 break;
3615 }
3616 break;
3617 default:
3618 elog(ERROR, "unrecognized window seek type: %d", seektype);
3619 abs_pos = mark_pos = 0;
3620 break;
3621 }
3622
3624 goto out_of_frame;
3625
3626
3628 goto out_of_frame;
3629
3630 if (isout)
3631 *isout = false;
3632 if (set_mark)
3636 econtext, isnull);
3637
3638out_of_frame:
3639 if (isout)
3640 *isout = true;
3641 *isnull = true;
3642 return (Datum) 0;
3643}
static void update_grouptailpos(WindowAggState *winstate)
static int row_is_in_frame(WindowAggState *winstate, int64 pos, TupleTableSlot *slot)
static bool window_gettupleslot(WindowObject winobj, int64 pos, TupleTableSlot *slot)
void WinSetMarkPosition(WindowObject winobj, int64 markpos)
static void update_frametailpos(WindowAggState *winstate)
static void update_frameheadpos(WindowAggState *winstate)
#define FRAMEOPTION_EXCLUDE_CURRENT_ROW
#define FRAMEOPTION_EXCLUDE_TIES
#define FRAMEOPTION_EXCLUDE_GROUP
#define FRAMEOPTION_EXCLUSION
TupleTableSlot * temp_slot_1
#define WINDOW_SEEK_CURRENT
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, 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 3376 of file nodeWindowAgg.c.
3379{
3383 bool gottuple;
3385
3387 winstate = winobj->winstate;
3390
3391 switch (seektype)
3392 {
3394 abs_pos = winstate->currentpos + relpos;
3395 break;
3397 abs_pos = relpos;
3398 break;
3401 abs_pos = winstate->spooled_rows - 1 + relpos;
3402 break;
3403 default:
3404 elog(ERROR, "unrecognized window seek type: %d", seektype);
3405 abs_pos = 0;
3406 break;
3407 }
3408
3410
3411 if (!gottuple)
3412 {
3413 if (isout)
3414 *isout = true;
3415 *isnull = true;
3416 return (Datum) 0;
3417 }
3418 else
3419 {
3420 if (isout)
3421 *isout = false;
3422 if (set_mark)
3426 econtext, isnull);
3427 }
3428}
static void spool_tuples(WindowAggState *winstate, int64 pos)
References WindowObjectData::argstates, Assert(), WindowAggState::currentpos, ExprContext::ecxt_outertuple, elog, ERROR, ExecEvalExpr(), list_nth(), ScanState::ps, PlanState::ps_ExprContext, spool_tuples(), WindowAggState::spooled_rows, WindowAggState::ss, WindowAggState::temp_slot_1, window_gettupleslot(), WINDOW_SEEK_CURRENT, WINDOW_SEEK_HEAD, WINDOW_SEEK_TAIL, WindowObjectIsValid, WinSetMarkPosition(), and WindowObjectData::winstate.
Referenced by leadlag_common().
◆ WinGetPartitionLocalMemory()
Definition at line 3236 of file nodeWindowAgg.c.
3237{
3239 if (winobj->localmem == NULL)
3243}
void * MemoryContextAllocZero(MemoryContext context, Size size)
MemoryContext partcontext
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()
◆ WinRowsArePeers()
Definition at line 3319 of file nodeWindowAgg.c.
3320{
3325 bool res;
3326
3328 winstate = winobj->winstate;
3330
3331
3333 return true;
3334
3335
3336
3337
3338
3341
3344 pos1);
3347 pos2);
3348
3349 res = are_peers(winstate, slot1, slot2);
3350
3353
3354 return res;
3355}
if(TABLE==NULL||TABLE_index==NULL)
static bool are_peers(WindowAggState *winstate, TupleTableSlot *slot1, TupleTableSlot *slot2)
TupleTableSlot * temp_slot_2
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
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()
Definition at line 3284 of file nodeWindowAgg.c.
3285{
3287
3289 winstate = winobj->winstate;
3290
3291 if (markpos < winobj->markpos)
3292 elog(ERROR, "cannot move WindowObject's mark position backward");
3294 if (markpos > winobj->markpos)
3295 {
3297 markpos - winobj->markpos,
3298 true);
3299 winobj->markpos = markpos;
3300 }
3302 if (markpos > winobj->seekpos)
3303 {
3305 markpos - winobj->seekpos,
3306 true);
3307 winobj->seekpos = markpos;
3308 }
3309}
void tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
bool tuplestore_skiptuples(Tuplestorestate *state, int64 ntuples, bool forward)
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(), rank_up(), window_row_number(), WinGetFuncArgInFrame(), and WinGetFuncArgInPartition().