* Return next partition bound in START/END/EVERY specification. */
| 760 | * Return next partition bound in START/END/EVERY specification. |
| 761 | */ |
| 762 | static bool |
| 763 | nextPartBound(PartEveryIterator *iter) |
| 764 | { |
| 765 | bool firstcall; |
| 766 | |
| 767 | firstcall = !iter->called; |
| 768 | iter->called = true; |
| 769 | |
| 770 | if (iter->plusexprstate) |
| 771 | { |
| 772 | /* |
| 773 | * Call (previous bound) + EVERY |
| 774 | */ |
| 775 | Datum next; |
| 776 | int32 cmpval; |
| 777 | bool isnull; |
| 778 | |
| 779 | /* If the previous partition reached END, we're done */ |
| 780 | if (iter->endReached) |
| 781 | return false; |
| 782 | |
| 783 | iter->plusexpr_params->params[0].isnull = false; |
| 784 | iter->plusexpr_params->params[0].value = iter->currEnd; |
| 785 | |
| 786 | next = ExecEvalExprSwitchContext(iter->plusexprstate, |
| 787 | GetPerTupleExprContext(iter->estate), |
| 788 | &isnull); |
| 789 | /* |
| 790 | * None of the built-in + operators can return NULL, but a user-defined |
| 791 | * operator could. |
| 792 | */ |
| 793 | if (isnull) |
| 794 | ereport(ERROR, |
| 795 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 796 | errmsg("could not compute next partition boundary with EVERY, plus-operator returned NULL"), |
| 797 | parser_errposition(iter->pstate, iter->every_location))); |
| 798 | |
| 799 | iter->currStart = iter->currEnd; |
| 800 | |
| 801 | /* Is the next bound greater than END? */ |
| 802 | cmpval = DatumGetInt32(FunctionCall2Coll(&iter->partkey->partsupfunc[0], |
| 803 | iter->partkey->partcollation[0], |
| 804 | next, |
| 805 | iter->endVal)); |
| 806 | if (cmpval >= 0) |
| 807 | { |
| 808 | iter->endReached = true; |
| 809 | iter->currEnd = iter->endVal; |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | /* |
| 814 | * Sanity check that the next bound is > previous bound. This prevents us |
| 815 | * from getting into an infinite loop if the + operator is not behaving. |
| 816 | */ |
| 817 | cmpval = DatumGetInt32(FunctionCall2Coll(&iter->partkey->partsupfunc[0], |
| 818 | iter->partkey->partcollation[0], |
| 819 | iter->currEnd, |
no test coverage detected