Avoid evaluating FOR PORTION OF bounds more than once
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
Hi Hackers,
Here is a fix for finding D9 from [0]/messages/by-id/CA+renyV6QLOJYmLo3gbsg1Y+Crho8NqME1jJXgPbO_NgxfBaKQ@mail.gmail.com.
Currently we can evaluate the expressions in FOR PORTION OF more than
once. If a function is declared STABLE but isn't really, that can
cause inconsistent results. Another way to reach the problem is by
using current_setting, and then calling set_config (for instance from
a trigger). I can't find any other avenues besides those two. I also
tried EvalPlanQual and a STABLE function reading from a table that
gets modified mid-statement by a trigger.
Arguably this is not really a bug, and the fix is somewhat involved
(using a PARAM_EXEC slot to pass the value around). But I wanted to
share a patch in case others think it needs to be fixed. It might
still be worth doing (though not in v19 IMO), since it saves an expr
evaluation every row. I skipped `Backpatch-through: 19` on this patch,
but I'll add it to future versions if we want it in this release.
[0]: /messages/by-id/CA+renyV6QLOJYmLo3gbsg1Y+Crho8NqME1jJXgPbO_NgxfBaKQ@mail.gmail.com
Yours,
--
Paul ~{:-)
pj@illuminatedcomputing.com