Skip to content

WAIT FOR command should do some query jumbling - #414

Open
pg-hub-mirror[bot] wants to merge 1 commit into
masterfrom
pg-hub/mirror-patch-20cb9af4d70a8722
Open

pg-hub-mirror[bot] wants to merge 1 commit into
masterfrom
pg-hub/mirror-patch-20cb9af4d70a8722

Conversation

@pg-hub-mirror

@pg-hub-mirror pg-hub-mirror Bot commented Sep 18, 2026

Copy link
Copy Markdown

Read-only mirror. Reply and review on pgsql-hackers; activity here is not sent upstream.

  • Original author: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
  • Mailing list: pgsql-hackers
  • Message-ID: CAPpHfdt1Zasx9AuXgn8w0fqcMHffqWcC4yPrVq-A5Ok+6DWY_A@mail.gmail.com
  • Original email

Patch files:


Hi!
On Thu, Sep 3, 2026 at 6:38 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:

Sami has also mentioned to me off-list that we may want something
smarter in terms of the management of the DefElems that include
strings, because we have other commands with contents that we may want
to normalize in some contexts, like an ALTER TABLE with a password as
one example. Perhaps it would be better to not rush that part.
Agreed, so v3 attached drops the generic part and does WAIT only.
Two things today: waits differing only in the timeout get an entry
each, and so does the same wait with its options written in another
order.
1 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '5ms')
1 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '7ms')
1 | WAIT FOR LSN $1 WITH (timeout '5ms', mode 'primary_flush')
With v3 those are one entry:
3 | WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout $2)
while the modes stay apart, as Sirisha asked for:
1 | WAIT FOR LSN $1 WITH (mode 'standby_replay', timeout $2, no_throw)
1 | WAIT FOR LSN $1 WITH (mode 'standby_write', timeout $2, no_throw)
WaitStmt.options gets a custom jumble function that walks the
recognized options in a fixed order instead of the order written,
records TIMEOUT as a constant, and jumbles MODE and NO_THROW as given.
No generic DefElem option normalization: what a value means differs
per option and only the command knows, which is the same problem
VariableSetStmt.jumble_args solves per grammar flavor.
DefElem gains arg_location, since DefElem.location points at the
option name -- recording that one normalizes the wrong token:
WAIT FOR LSN $1 WITH (mode 'primary_flush', $2 '5ms')
and the argument node is a bare String or Integer, which carries no
location at all. Nothing else reads the new field, so no other
statement changes.
One wart left alone: "WITH (no_throw)" and "WITH (no_throw true)" are
still separate entries, as VACUUM (ANALYZE) and VACUUM (ANALYZE true)
are today. Resolving it would mean calling defGetBoolean() while
jumbling, which can throw.
Passwords in pg_stat_statements are untouched by this and can go to
their own thread.


Regards,
Alexander Korotkov
Supabase

The LSN target has been normalized since 447aae1 and the follow-up in
this thread, but the WITH clause has not, so waits that differ only in how
long they may take get an entry each, and writing the same options in a
different order gets another one:

  WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '5ms')
  WAIT FOR LSN $1 WITH (mode 'primary_flush', timeout '7ms')
  WAIT FOR LSN $1 WITH (timeout '5ms', mode 'primary_flush')

Give WaitStmt.options a custom jumble function that walks the recognized
options in a fixed order rather than in the order written, so the last of
those joins the first.  Record TIMEOUT as a constant, since it only bounds
how long the command may wait, which merges the first two and prints the
value as a parameter.  MODE and NO_THROW select what the command does, so
their values are still jumbled and each mode keeps its own entry.

Do not normalize option values generically.  What a value means differs
per option, and only the command knows: the parser has the same problem
with SET and solves it with VariableSetStmt.jumble_args, set per grammar
flavor.  DefElem.arg_location is added for the benefit of the above, but
nothing else reads it, so no other statement changes.

Discussion: https://postgr.es/m/1f04f78c-2cfa-47a0-997f-f02572cd10eb%40eisentraut.org
@pg-hub-mirror pg-hub-mirror Bot added source:pgsql-hackers Mirrored from pgsql-hackers type:patch Mail thread contains a PostgreSQL patch area:wal Write-ahead logging and recovery area:sql SQL language or commands area:vacuum VACUUM or autovacuum labels Sep 18, 2026
@pg-hub-mirror pg-hub-mirror Bot locked and limited conversation to collaborators Sep 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area:sql SQL language or commands area:vacuum VACUUM or autovacuum area:wal Write-ahead logging and recovery source:pgsql-hackers Mirrored from pgsql-hackers type:patch Mail thread contains a PostgreSQL patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant