Avoid evaluating FOR PORTION OF bounds more than once - Mailing list pgsql-hackers

From Paul A Jungwirth
Subject Avoid evaluating FOR PORTION OF bounds more than once
Date
Msg-id CA+renyU4yDpiG-drzF40GfVxiMpmByDQEDZwpxODYa5ztwP6Jw@mail.gmail.com
Whole thread
Responses Re: [PATCH] Preserve replication origin OIDs in pg_upgrade
List pgsql-hackers
Hi Hackers,

Here is a fix for finding D9 from [0].

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] https://www.postgresql.org/message-id/CA%2BrenyV6QLOJYmLo3gbsg1Y%2BCrho8NqME1jJXgPbO_NgxfBaKQ%40mail.gmail.com

Yours,

-- 
Paul              ~{:-)
pj@illuminatedcomputing.com

Attachment

pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: proposal for a new minor release schedule
Next
From: Kirk Wolak
Date:
Subject: Re: [PATCH v1 0/7] Wait event timing and tracing instrumentation