From: Jeff Davis <pgsql@j-davis.com>
To: Manu <manuelreyesbravo@gmail.com>
Cc: James Hunter <james.hunter.pg@gmail.com>
Cc: Álvaro Herrera <alvherre@kurilemu.de>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators
Date: Tue, 06 Oct 2026 10:56:54 -0700
Message-ID: <227a5a38f1536ea9d9dc84ea533f2182876ee56f.camel@j-davis.com> (raw)
In-Reply-To: <179106756531.274884.9866634099979671297@gmail.com>
References: <9800a3044cf2f2d948def3e5b68f8eda61a82d22.camel@j-davis.com>
<179106756531.274884.9866634099979671297@gmail.com>
On Sat, 2026-10-03 at 19:46 -0300, Manu wrote:
> Each Plan node gets a workmem field...The executor uses the node's
> value...I first tried copying work_mem into the field at plan time.
> Then SET
> LOCAL work_mem inside a PL/pgSQL function no longer reached a query
> whose plan was already cached: it wrote a 13 MB temporary file that
> master does not. Replanning cached plans when work_mem changes fixes
> that, but cost 47% of the tps in a pgbench run that changes work_mem
> in
> every transaction before a prepared 3-way join.
Regarding the previous discussion here:
https://www.postgresql.org/message-id/2a2b28e2ea677e3cec2850b2dd38b467bf1291fb.camel%40j-davis.com
IIUC, you resolve the issue by introducing a special zero value, which
preserves the existing behavior by default, and only an extension can
set it to a non-zero value. There's no auto-replan, so using an
extension would get behavior (a) described in the above thread.
I generally like that approach. It allows some experimentation with
planner hooks without changing existing behavior. It also avoids some
difficulty transmitting work_mem to places that don't have easy access
to the Plan structure.
It's essentially a refactor, so the cost is ~200 lines, some code
churn, and extra function parameters. I didn't review all the details
yet, but if a real extension actually uses this, that seems reasonable
to me.
Regards,
Jeff Davis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: pgsql@j-davis.com, manuelreyesbravo@gmail.com, james.hunter.pg@gmail.com, alvherre@kurilemu.de
Subject: Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators
In-Reply-To: <227a5a38f1536ea9d9dc84ea533f2182876ee56f.camel@j-davis.com>
References: <9800a3044cf2f2d948def3e5b68f8eda61a82d22.camel@j-davis.com> <179106756531.274884.9866634099979671297@gmail.com> <227a5a38f1536ea9d9dc84ea533f2182876ee56f.camel@j-davis.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox