Re: Call CalculateShmemSize() only once

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Heikki Linnakangas <heikki(dot)linnakangas(at)databricks(dot)com>
Subject: Re: Call CalculateShmemSize() only once
Date: 2026-11-07 14:31:07
Message-ID: CAExHW5vKqR7+stx=dKMpnRcMyZssexY4fvjL4k=gi_jdb=Y97g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 6, 2026 at 4:46 PM Xuneng Zhou <xunengzhou(at)gmail(dot)com> wrote:
>
> Erroring out can help to stop the misake where it occurs. A build
> without assert could accept the bad call, then fail later somewhere
> else. It might make the problem a bit hard to understand. That said,
> assert seems ok here since we haven't found code can make that bad
> call.
>

Agreed that an ERROR would make an invalid call easier to diagnose in
a build without assertions. I think Assert is sufficient here because
this checks an internal lifecycle invariant, consistent with the other
state-transition assertions. The current callers calculate the size
once per shared-memory initialization cycle, and requests made after
sizing are already rejected by runtime checks.

> A nit - the new state in code is SRS_SIZED, but the commit message
> says SRS_SIZING.

Good catch. Fixed in the attached patch: the code already uses
SRS_SIZED; I’ve corrected the commit message to match.

--
Best Wishes,
Ashutosh Bapat

Attachment Content-Type Size
v20261107-0001-Call-CalculateShmemSize-only-once-when-cre.patch text/x-patch 8.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeevan Chalke 2026-11-07 14:35:02 Re: PL/pgSQL: allow parallel query for assignment statements
Previous Message Pierre Forstmann 2026-11-07 14:10:45 Re: PL/pgSQL: allow parallel query for assignment statements