* assignSortGroupRef * Assign the targetentry an unused ressortgroupref, if it doesn't * already have one. Return the assigned or pre-existing refnumber. * * 'tlist' is the targetlist containing (or to contain) the given targetentry. */
| 3770 | * 'tlist' is the targetlist containing (or to contain) the given targetentry. |
| 3771 | */ |
| 3772 | Index |
| 3773 | assignSortGroupRef(TargetEntry *tle, List *tlist) |
| 3774 | { |
| 3775 | Index maxRef; |
| 3776 | ListCell *l; |
| 3777 | |
| 3778 | if (tle->ressortgroupref) /* already has one? */ |
| 3779 | return tle->ressortgroupref; |
| 3780 | |
| 3781 | /* easiest way to pick an unused refnumber: max used + 1 */ |
| 3782 | maxRef = 0; |
| 3783 | foreach(l, tlist) |
| 3784 | { |
| 3785 | Index ref = ((TargetEntry *) lfirst(l))->ressortgroupref; |
| 3786 | |
| 3787 | if (ref > maxRef) |
| 3788 | maxRef = ref; |
| 3789 | } |
| 3790 | tle->ressortgroupref = maxRef + 1; |
| 3791 | return tle->ressortgroupref; |
| 3792 | } |
| 3793 | |
| 3794 | /* |
| 3795 | * targetIsInSortList |
no test coverage detected