I said:
> SPI is doing CommandCounterIncrements at bizarre times, and in
> particular you get fewer CommandCounterIncrements while planning
> and executing a plpgsql function than you do while re-executing
> an already-planned one.
s/fewer/more/ ... guess I'm not fully awake yet ... but anyway,
SPI's handling of CommandCounterIncrement is certainly broken.
Particularly for cursors --- a CCI for every FETCH will not do,
you want the whole scan to be run with the same commandId.
regards, tom lane