* advance_windowaggregate_base * Remove the oldest tuple from an aggregation. * * This is very much like advance_windowaggregate, except that we will call * the inverse transition function (which caller must have checked is * available). * * Returns true if we successfully removed the current row from this * aggregate, false if not (in the latter case, caller is responsible * for cleaning
| 511 | * for cleaning up by restarting the aggregation). |
| 512 | */ |
| 513 | static bool |
| 514 | advance_windowaggregate_base(WindowAggState *winstate, |
| 515 | WindowStatePerFunc perfuncstate, |
| 516 | WindowStatePerAgg peraggstate) |
| 517 | { |
| 518 | LOCAL_FCINFO(fcinfo, FUNC_MAX_ARGS); |
| 519 | WindowFuncExprState *wfuncstate = perfuncstate->wfuncstate; |
| 520 | int numArguments = perfuncstate->numArguments; |
| 521 | Datum newVal; |
| 522 | ListCell *arg; |
| 523 | int i; |
| 524 | MemoryContext oldContext; |
| 525 | ExprContext *econtext = winstate->tmpcontext; |
| 526 | ExprState *filter = wfuncstate->aggfilter; |
| 527 | |
| 528 | oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); |
| 529 | |
| 530 | /* Skip anything FILTERed out */ |
| 531 | if (filter) |
| 532 | { |
| 533 | bool isnull; |
| 534 | Datum res = ExecEvalExpr(filter, econtext, &isnull); |
| 535 | |
| 536 | if (isnull || !DatumGetBool(res)) |
| 537 | { |
| 538 | MemoryContextSwitchTo(oldContext); |
| 539 | return true; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | /* We start from 1, since the 0th arg will be the transition value */ |
| 544 | i = 1; |
| 545 | foreach(arg, wfuncstate->args) |
| 546 | { |
| 547 | ExprState *argstate = (ExprState *) lfirst(arg); |
| 548 | |
| 549 | fcinfo->args[i].value = ExecEvalExpr(argstate, econtext, |
| 550 | &fcinfo->args[i].isnull); |
| 551 | i++; |
| 552 | } |
| 553 | |
| 554 | if (peraggstate->invtransfn.fn_strict) |
| 555 | { |
| 556 | /* |
| 557 | * For a strict (inv)transfn, nothing happens when there's a NULL |
| 558 | * input; we just keep the prior transValue. Note transValueCount |
| 559 | * doesn't change either. |
| 560 | */ |
| 561 | for (i = 1; i <= numArguments; i++) |
| 562 | { |
| 563 | if (fcinfo->args[i].isnull) |
| 564 | { |
| 565 | MemoryContextSwitchTo(oldContext); |
| 566 | return true; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 |
no test coverage detected