pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
WAIT FOR command should do some query jumbling
19+ messages / 7 participants
[nested] [flat]

Commits from this thread:
  2026-09-02 282111b45c 7635a32067  Apply some query jumbling to WAIT FOR LSN
* WAIT FOR command should do some query jumbling
@ 2026-08-28 21:48 Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Peter Eisentraut @ 2026-08-28 21:48 UTC (permalink / raw)
  To: pgsql-hackers; +Cc: Alexander Korotkov <akorotkov@postgresql.org>

Right now, WAIT FOR commands are recorded literally in 
pg_stat_statements.  I think the actual LSN value should be replaced by 
some placeholder, like

WAIT FOR LSN $1

Otherwise, a client library or framework that runs this command 
repeatedly would needlessly spam pg_stat_statements.

The query jumbling facilities should be used to handle this.






^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
@ 2026-08-28 23:06 ` sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 19:12   ` Re: WAIT FOR command should do some query jumbling Rithvika Devisetti <devisettirithvika@gmail.com>
  0 siblings, 2 replies; 19+ messages in thread

From: sirisha chamarthi @ 2026-08-28 23:06 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

Hi Peter,

On Fri, Aug 28, 2026 at 2:48 PM Peter Eisentraut <peter@eisentraut.org>
wrote:

> Right now, WAIT FOR commands are recorded literally in
> pg_stat_statements.  I think the actual LSN value should be replaced by
> some placeholder, like
>
> WAIT FOR LSN $1
>
> Otherwise, a client library or framework that runs this command
> repeatedly would needlessly spam pg_stat_statements.
>
> The query jumbling facilities should be used to handle this.
>

+1 to your suggestion. Please find the attached patch to address this issue.

Regards,
Sirisha

Attachments:

v1-0001-Jumble-WAIT-FOR-LSN-target.patch (application/octet-stream, 2.8K) download diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_stat_statements/expected/utility.out index e4d6564ea5b..acb95f34f1b 100644 --- a/contrib/pg_stat_statements/expected/utility.out +++ b/contrib/pg_stat_statements/expected/utility.out @@ -719,6 +719,34 @@ SELECT pg_stat_statements_reset() IS NOT NULL AS t; t (1 row) +-- WAIT FOR LSN +-- Different target LSNs should be normalized into one entry. +WAIT FOR LSN '0/0' WITH (MODE 'primary_flush'); + status +--------- + success +(1 row) + +WAIT FOR LSN '0/1' WITH (MODE 'primary_flush'); + status +--------- + success +(1 row) + +SELECT calls, rows, query + FROM pg_stat_statements + WHERE query LIKE 'WAIT FOR LSN%'; + calls | rows | query +-------+------+--------------------------------------------- + 2 | 0 | WAIT FOR LSN $1 WITH (MODE 'primary_flush') +(1 row) + +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + t +--- + t +(1 row) + -- Special cases. Keep these ones at the end to avoid conflicts. SET SCHEMA 'foo'; SET SCHEMA 'public'; diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_statements/sql/utility.sql index dd97203c210..39ecac37e70 100644 --- a/contrib/pg_stat_statements/sql/utility.sql +++ b/contrib/pg_stat_statements/sql/utility.sql @@ -365,6 +365,15 @@ DROP TABLE pgss_select_into; SELECT pg_stat_statements_reset() IS NOT NULL AS t; +-- WAIT FOR LSN +-- Different target LSNs should be normalized into one entry. +WAIT FOR LSN '0/0' WITH (MODE 'primary_flush'); +WAIT FOR LSN '0/1' WITH (MODE 'primary_flush'); +SELECT calls, rows, query + FROM pg_stat_statements + WHERE query LIKE 'WAIT FOR LSN%'; +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + -- Special cases. Keep these ones at the end to avoid conflicts. SET SCHEMA 'foo'; SET SCHEMA 'public'; diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index a33c3aaeeb2..eea540106de 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -17300,6 +17300,7 @@ WaitStmt: WaitStmt *n = makeNode(WaitStmt); n->lsn_literal = $4; n->options = $5; + n->lsn_location = @4; $$ = (Node *) n; } ; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index d3835af8f9e..a4c21b8562c 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -4606,8 +4606,11 @@ typedef struct DropSubscriptionStmt typedef struct WaitStmt { NodeTag type; - char *lsn_literal; /* LSN string from grammar */ + /* LSN string from grammar */ + char *lsn_literal pg_node_attr(query_jumble_ignore); List *options; /* List of DefElem nodes */ + /* token location, or -1 if unknown */ + ParseLoc lsn_location pg_node_attr(query_jumble_location); } WaitStmt;
^ permalink raw reply [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
@ 2026-08-30 01:02   ` Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 20:35     ` Re: WAIT FOR command should do some query jumbling Rithvika Devisetti <devisettirithvika@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  1 sibling, 2 replies; 19+ messages in thread

From: Sami Imseih @ 2026-08-30 01:02 UTC (permalink / raw)
  To: sirisha chamarthi <sirichamarthi22@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Michael Paquier <michael@paquier.xyz>

Hi,

> The query jumbling facilities should be used to handle this.

+1 for this. I think we need to do a bit more than what is suggested
in v1-0001, which only normalizes the target LSN. I think we should
also look at the rest of the rest of the WAIT FOR syntax and normalize
option values, for example

```
    WAIT FOR LSN 'FFFFFFFF/FFFFFFFF'
      WITH (MODE 'primary_flush', TIMEOUT '1ms', NO_THROW);

    WAIT FOR LSN 'FFFFFFFE/FFFFFFFF'
      WITH (MODE 'primary_flush', TIMEOUT '2ms', NO_THROW);
```

These should normalize to one pg_stat_statements entry

```
    WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)
```

Because these options are carried as DefElem, I think we should also
track DefElem arg_location, and then statement parse nodes with such
DefElem option lists can use pg_node_attr(custom_query_jumble) to
traverse those lists and normalize the option values.

WAIT FOR is one case, but I think the same approach could also be
useful for other utility statements such as VACUUM and ALTER ROLE. For
example, ALTER ROLE could normalize PASSWORD and VALID UNTIL. I have
kept this series focused on WAIT FOR for now, though.

So, attached in v2, v2-0001 adds the DefElem arg_location tracking,
and v2-0002 adds the WAIT FOR jumbling changes.
JumbleDefElemOptions() is a small helper in queryjumblefuncs.c that
other statements can use to implement the same kind of option
jumbling.

CC'ing Michael also to get his thoughts on the approach.

--
Sami Imseih
Amazon Web Services (AWS)

Attachments: download all (2 files, .tar.gz)

v2-0001-Track-DefElem-argument-locations-to-allow-query-n.patch (application/octet-stream, 2.1K) download From 1ee264e02b073bc324156d85ac2985d873e5a55b Mon Sep 17 00:00:00 2001 From: Sami Imseih <samimseih.pg@gmail.com> Date: Sat, 29 Aug 2026 19:39:05 +0000 Subject: [PATCH v2 1/4] Track DefElem argument locations to allow query normalization This records DefElem argument locations so utility statements that use DefElem for options can normalize the supplied argument values. DefElem now carries an arg_location field, initialized to -1 when unset, and gram.y is taught to record the location of the element value. Future patches will use this in custom query jumbling for specific utility statements. --- src/backend/nodes/makefuncs.c | 2 ++ src/backend/parser/gram.y | 1 + src/include/nodes/parsenodes.h | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index cdc02b274ff..628f4bb0a48 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -643,6 +643,7 @@ makeDefElem(char *name, Node *arg, int location) res->arg = arg; res->defaction = DEFELEM_UNSPEC; res->location = location; + res->arg_location = -1; return res; } @@ -662,6 +663,7 @@ makeDefElemExtended(char *nameSpace, char *name, Node *arg, res->arg = arg; res->defaction = defaction; res->location = location; + res->arg_location = -1; return res; } diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 2df39a48fc6..65b2b4384f8 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -1225,6 +1225,7 @@ utility_option_elem: utility_option_name utility_option_arg { $$ = makeDefElem($1, $2, @1); + $$->arg_location = @2; } ; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index d3835af8f9e..afe09b1f7a9 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -864,6 +864,8 @@ typedef struct DefElem * TypeName */ DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ ParseLoc location; /* token location, or -1 if unknown */ + /* argument location, or -1 if unknown */ + ParseLoc arg_location; } DefElem; /* -- 2.47.3
v2-0002-Normalize-WAIT-FOR-WITH-clause-values-in-pg_stat_.patch (application/octet-stream, 5.5K) download From 8fa533bf528e420ec322ec17000617c75e2638a0 Mon Sep 17 00:00:00 2001 From: Sami Imseih <samimseih.pg@gmail.com> Date: Sat, 29 Aug 2026 19:40:14 +0000 Subject: [PATCH v2 2/4] Normalize WAIT FOR WITH clause values in pg_stat_statements Teach WaitStmt option jumbling to record DefElem argument locations, so MODE and TIMEOUT values normalize to one pg_stat_statements entry. Introduce JumbleDefElemOptions() as a small helper for other statements that need the same DefElem option jumbling. --- .../pg_stat_statements/expected/utility.out | 26 +++++++++++++++++ contrib/pg_stat_statements/sql/utility.sql | 6 ++++ src/backend/nodes/queryjumblefuncs.c | 28 +++++++++++++++++++ src/backend/parser/gram.y | 1 + src/include/nodes/parsenodes.h | 11 ++++++-- 5 files changed, 70 insertions(+), 2 deletions(-) diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_stat_statements/expected/utility.out index e4d6564ea5b..f2e53e47272 100644 --- a/contrib/pg_stat_statements/expected/utility.out +++ b/contrib/pg_stat_statements/expected/utility.out @@ -719,6 +719,32 @@ SELECT pg_stat_statements_reset() IS NOT NULL AS t; t (1 row) +-- WAIT FOR +WAIT FOR LSN 'FFFFFFFF/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT '1ms', NO_THROW); + status +--------- + timeout +(1 row) + +WAIT FOR LSN 'FFFFFFFE/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT '2ms', NO_THROW); + status +--------- + timeout +(1 row) + +SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C"; + calls | rows | query +-------+------+------------------------------------------------------ + 1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t + 2 | 0 | WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW) +(2 rows) + +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + t +--- + t +(1 row) + -- Special cases. Keep these ones at the end to avoid conflicts. SET SCHEMA 'foo'; SET SCHEMA 'public'; diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_statements/sql/utility.sql index dd97203c210..fb843fffa6c 100644 --- a/contrib/pg_stat_statements/sql/utility.sql +++ b/contrib/pg_stat_statements/sql/utility.sql @@ -365,6 +365,12 @@ DROP TABLE pgss_select_into; SELECT pg_stat_statements_reset() IS NOT NULL AS t; +-- WAIT FOR +WAIT FOR LSN 'FFFFFFFF/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT '1ms', NO_THROW); +WAIT FOR LSN 'FFFFFFFE/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT '2ms', NO_THROW); +SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C"; +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + -- Special cases. Keep these ones at the end to avoid conflicts. SET SCHEMA 'foo'; SET SCHEMA 'public'; diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index 094d2872644..53b08285fcf 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -70,6 +70,7 @@ static void FlushPendingNulls(JumbleState *jstate); static void RecordConstLocation(JumbleState *jstate, bool extern_param, int location, int len); +static void JumbleDefElemOptions(JumbleState *jstate, List *options); static void _jumbleNode(JumbleState *jstate, Node *node); static void _jumbleList(JumbleState *jstate, Node *node); static void _jumbleElements(JumbleState *jstate, List *elements, Node *node); @@ -79,6 +80,9 @@ static void _jumbleVariableSetStmt(JumbleState *jstate, Node *node); static void _jumbleRangeTblEntry_eref(JumbleState *jstate, RangeTblEntry *rte, Alias *expr); +static void _jumbleWaitStmt_options(JumbleState *jstate, + WaitStmt *ws, + List *options); /* * Given a possibly multi-statement source string, confine our attention to the @@ -774,6 +778,30 @@ _jumbleRangeTblEntry_eref(JumbleState *jstate, JUMBLE_STRING(aliasname); } +static void +JumbleDefElemOptions(JumbleState *jstate, List *options) +{ + ListCell *l; + + foreach(l, options) + { + DefElem *expr = lfirst_node(DefElem, l); + + JUMBLE_STRING(defnamespace); + JUMBLE_STRING(defname); + JUMBLE_FIELD(defaction); + RecordConstLocation(jstate, false, expr->arg_location, -1); + } +} + +static void +_jumbleWaitStmt_options(JumbleState *jstate, + WaitStmt *ws, + List *options) +{ + JumbleDefElemOptions(jstate, options); +} + /* * CompLocation: comparator for qsorting LocationLen structs by location */ diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 65b2b4384f8..bff0b2a46b0 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -17300,6 +17300,7 @@ WaitStmt: { WaitStmt *n = makeNode(WaitStmt); n->lsn_literal = $4; + n->lsn_location = @4; n->options = $5; $$ = (Node *) n; } diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index afe09b1f7a9..86eb9512d08 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -4608,8 +4608,15 @@ typedef struct DropSubscriptionStmt typedef struct WaitStmt { NodeTag type; - char *lsn_literal; /* LSN string from grammar */ - List *options; /* List of DefElem nodes */ + + /* LSN string from grammar */ + char *lsn_literal pg_node_attr(query_jumble_ignore); + + /* List of DefElem nodes */ + List *options pg_node_attr(custom_query_jumble); + + /* LSN literal token location, or -1 if unknown */ + ParseLoc lsn_location pg_node_attr(query_jumble_location); } WaitStmt; -- 2.47.3
^ permalink raw reply [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-30 20:35     ` Rithvika Devisetti <devisettirithvika@gmail.com>
  1 sibling, 0 replies; 19+ messages in thread

From: Rithvika Devisetti @ 2026-08-30 20:35 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Michael Paquier <michael@paquier.xyz>

Hello Sami and Sirisha,

Thank You very much for the patches.

I tested the v2 series on with a clean meson build (cassert enabled). Both
patches apply cleanly to master
(92819e57945) and the full test suite passes: 362 OK, 0 failures.

Your example normalizes as described:

  WAIT FOR LSN 'FFFFFFFF/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT
'1ms', NO_THROW);
  WAIT FOR LSN 'FFFFFFFE/FFFFFFFF' WITH (MODE 'primary_flush', TIMEOUT
'2ms', NO_THROW);

   calls |                        query
  -------+------------------------------------------------------
       2 | WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)

A few other cases I checked, all behaving sensibly:

- TIMEOUT 1000 and TIMEOUT '1ms' normalize to the same entry despite
  the different literal types.
- Different option order or a different number of options produce
  separate entries, which seems right since the query text differs.
- Argument-less options (NO_THROW) are fine: arg_location stays -1 and
  RecordConstLocation() already ignores negative locations.
- VACUUM/EXPLAIN/COPY still record their option values literally, as
  expected since 0001 only tracks arg_location without changing
  jumbling for statements that haven't opted in.

Agreed the helper looks reusable for VACUUM and ALTER ROLE later.

Regards,
Rithvika Devisetti

On Sat, Aug 29, 2026 at 6:03 PM Sami Imseih <samimseih.pg@gmail.com> wrote:

> Hi,
>
> > The query jumbling facilities should be used to handle this.
>
> +1 for this. I think we need to do a bit more than what is suggested
> in v1-0001, which only normalizes the target LSN. I think we should
> also look at the rest of the rest of the WAIT FOR syntax and normalize
> option values, for example
>
> ```
>     WAIT FOR LSN 'FFFFFFFF/FFFFFFFF'
>       WITH (MODE 'primary_flush', TIMEOUT '1ms', NO_THROW);
>
>     WAIT FOR LSN 'FFFFFFFE/FFFFFFFF'
>       WITH (MODE 'primary_flush', TIMEOUT '2ms', NO_THROW);
> ```
>
> These should normalize to one pg_stat_statements entry
>
> ```
>     WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)
> ```
>
> Because these options are carried as DefElem, I think we should also
> track DefElem arg_location, and then statement parse nodes with such
> DefElem option lists can use pg_node_attr(custom_query_jumble) to
> traverse those lists and normalize the option values.
>
> WAIT FOR is one case, but I think the same approach could also be
> useful for other utility statements such as VACUUM and ALTER ROLE. For
> example, ALTER ROLE could normalize PASSWORD and VALID UNTIL. I have
> kept this series focused on WAIT FOR for now, though.
>
> So, attached in v2, v2-0001 adds the DefElem arg_location tracking,
> and v2-0002 adds the WAIT FOR jumbling changes.
> JumbleDefElemOptions() is a small helper in queryjumblefuncs.c that
> other statements can use to implement the same kind of option
> jumbling.
>
> CC'ing Michael also to get his thoughts on the approach.
>
> --
> Sami Imseih
> Amazon Web Services (AWS)
>

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-30 21:34     ` sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  1 sibling, 1 reply; 19+ messages in thread

From: sirisha chamarthi @ 2026-08-30 21:34 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Michael Paquier <michael@paquier.xyz>

Hi Sami

On Sat, Aug 29, 2026 at 6:03 PM Sami Imseih <samimseih.pg@gmail.com> wrote:

> Hi,
>
> > The query jumbling facilities should be used to handle this.
>
> +1 for this. I think we need to do a bit more than what is suggested
> in v1-0001, which only normalizes the target LSN. I think we should
> also look at the rest of the rest of the WAIT FOR syntax and normalize
> option values, for example
>
> ```
>     WAIT FOR LSN 'FFFFFFFF/FFFFFFFF'
>       WITH (MODE 'primary_flush', TIMEOUT '1ms', NO_THROW);
>
>     WAIT FOR LSN 'FFFFFFFE/FFFFFFFF'
>       WITH (MODE 'primary_flush', TIMEOUT '2ms', NO_THROW);
> ```
>
> These should normalize to one pg_stat_statements entry
>
> ```
>     WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)
> ```
>
> Because these options are carried as DefElem, I think we should also
> track DefElem arg_location, and then statement parse nodes with such
> DefElem option lists can use pg_node_attr(custom_query_jumble) to
> traverse those lists and normalize the option values.
>
> WAIT FOR is one case, but I think the same approach could also be
> useful for other utility statements such as VACUUM and ALTER ROLE. For
> example, ALTER ROLE could normalize PASSWORD and VALID UNTIL. I have
> kept this series focused on WAIT FOR for now, though.
>
> So, attached in v2, v2-0001 adds the DefElem arg_location tracking,
> and v2-0002 adds the WAIT FOR jumbling changes.
> JumbleDefElemOptions() is a small helper in queryjumblefuncs.c that
> other statements can use to implement the same kind of option
> jumbling.
>
> CC'ing Michael also to get his thoughts on the approach.
>

Thanks Sami for the v2 patch! This patch applied cleanly and the tests
passed.
One observation with this approach is at times option can have different
meanings
and that may be lost during jumbling. For example, in the WAL FOR LSN case,
4 different MODEs are defined with different semantics and this patch does
not differentiate.

WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)


Regards,
Sirisha

>

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
@ 2026-08-30 22:27       ` Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 19+ messages in thread

From: Sami Imseih @ 2026-08-30 22:27 UTC (permalink / raw)
  To: sirisha chamarthi <sirichamarthi22@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Michael Paquier <michael@paquier.xyz>

Hi,

One observation with this approach is at times option can have different
> meanings
> and that may be lost during jumbling. For example, in the WAL FOR LSN case,
> 4 different MODEs are defined with different semantics and this patch does
> not differentiate.
>
> WAIT FOR LSN $1 WITH (MODE $2, TIMEOUT $3, NO_THROW)
>

I thought about this, but did not think it will be useful to keep MODE
without normalization, since we are normalizing the LSN. But, perhaps
others have a different opinion?

--
Sami Imseih

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-31 02:43         ` Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Michael Paquier @ 2026-08-31 02:43 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

On Sun, Aug 30, 2026 at 05:27:59PM -0500, Sami Imseih wrote:
> I thought about this, but did not think it will be useful to keep MODE
> without normalization, since we are normalizing the LSN. But, perhaps
> others have a different opinion?

I can see the lack of normalization for the LSN as a bug, but the
option patterns in a WITH clause is IMO more debatable.  I think that
we should collect more data from the field before setting down on a
behavior we may regret.  I can partially get behind a normalization of
the timeout, but I am less clear about the MODE and NO_THROW, as it
could be useful to split them.

In terms of v19, it seems to me that just ignoring the LSN part is
enough as a LSN is a moving target, so I would agree about using v1
for now, backpatch it down to v19.  We should consider some of the
patterns covered by v2 once we know more about how users use this
feature.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
@ 2026-08-31 02:56           ` Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 19+ messages in thread

From: Sami Imseih @ 2026-08-31 02:56 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

>
> I can see the lack of normalization for the LSN as a bug, but the
> option patterns in a WITH clause is IMO more debatable.  I think that
> we should collect more data from the field before setting down on a
> behavior we may regret.  I can partially get behind a normalization of
> the timeout, but I am less clear about the MODE and NO_THROW, as it
> could be useful to split them.


IMO, LSN and timeout are both the minimum we should normalize here.

I am also not sure how tools will use this feature, but what makes timeout
safe IMO is the fact that the "timeout" values across many executions that
collapse into a single entry can be understood by the  *_exec_time fields.

--
Sami

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-31 07:38             ` Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Michael Paquier @ 2026-08-31 07:38 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>

On Sun, Aug 30, 2026 at 09:56:29PM -0500, Sami Imseih wrote:
> IMO, LSN and timeout are both the minimum we should normalize here.
> 
> I am also not sure how tools will use this feature, but what makes timeout
> safe IMO is the fact that the "timeout" values across many executions that
> collapse into a single entry can be understood by the  *_exec_time fields.

I see the traction here, but I cannot really get fully convinced by a
grouping of the timeouts without more input.  As a whole, I think that
Sirisha's patch is fine enough on its own.

Adding Nathan with his RMT hat on for comments regarding a potential
backpatch to v19, so as we have a fixed query ID with v20.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
@ 2026-08-31 12:20               ` Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Sami Imseih @ 2026-08-31 12:20 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>; Nathan Bossart <nathandbossart@gmail.com>

>
> I see the traction here, but I cannot really get fully convinced by a
> grouping of the timeouts without more input.  As a whole, I think that
> Sirisha's patch is fine enough on its own.
>

Perhaps LSN is enough for now as it will be the value that will vary the
most with heavy usage. I don't know how often TIMEOUT values will
vary however, so I'll drop the options normalization idea for now.

--
Sami

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-31 14:34                 ` Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Nathan Bossart @ 2026-08-31 14:34 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

I'm still digging into the details here, but what are folks' thoughts on
how critical this patch is for v19?  IOW is it a big deal if we leave it
out of v19 and put it in v20?  Or should the pg_stat_statements spam be a
blocker for its release?

-- 
nathan





^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
@ 2026-08-31 15:08                   ` Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Sami Imseih @ 2026-08-31 15:08 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

> I'm still digging into the details here, but what are folks' thoughts on
> how critical this patch is for v19?  IOW is it a big deal if we leave it
> out of v19 and put it in v20?  Or should the pg_stat_statements spam be a
> blocker for its release?


I am not sure if I would call it a blocker. The pg_stat_statements spam will
be confined to a standby, unless the MODE used is primary_flush, which
ISTM will be the lesser used case. But for both cases, the workaround is
to disable utility statement tracking. So, there is a workaround.

This is very much similar to how lack of SAVEPOINT normalization with
many unique savepoint names would cause pg_stat_statements before we
fixed that.

But if we go with v1-, this seems like a simple enough fix to get it, if
there
is still a chance to do so.

--
Sami

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
@ 2026-08-31 16:28                     ` Nathan Bossart <nathandbossart@gmail.com>
  2026-09-02 05:16                       ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 19+ messages in thread

From: Nathan Bossart @ 2026-08-31 16:28 UTC (permalink / raw)
  To: Sami Imseih <samimseih.pg@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

On Mon, Aug 31, 2026 at 10:08:54AM -0500, Sami Imseih wrote:
> But if we go with v1-, this seems like a simple enough fix to get it, if
> there is still a chance to do so.

Yeah, after staring at this some more, v1 seems reasonable to proceed with
for v19 from an RMT perspective.  I've alerted Melanie and Heikki in case
they want to share opinions, too.

-- 
nathan






^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
@ 2026-09-02 05:16                       ` Michael Paquier <michael@paquier.xyz>
  2026-09-02 12:53                         ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Michael Paquier @ 2026-09-02 05:16 UTC (permalink / raw)
  To: Nathan Bossart <nathandbossart@gmail.com>; +Cc: Sami Imseih <samimseih.pg@gmail.com>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

On Mon, Aug 31, 2026 at 11:28:13AM -0500, Nathan Bossart wrote:
> Yeah, after staring at this some more, v1 seems reasonable to proceed with
> for v19 from an RMT perspective.  I've alerted Melanie and Heikki in case
> they want to share opinions, too.

Hearing nothing, I have expanded the tests in v1 with more option
patterns, and applied it down to v19.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-09-02 05:16                       ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
@ 2026-09-02 12:53                         ` Alexander Korotkov <aekorotkov@gmail.com>
  2026-09-03 03:38                           ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 19+ messages in thread

From: Alexander Korotkov @ 2026-09-02 12:53 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Sami Imseih <samimseih.pg@gmail.com>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

On Wed, Sep 2, 2026 at 8:16 AM Michael Paquier <michael@paquier.xyz> wrote:
> On Mon, Aug 31, 2026 at 11:28:13AM -0500, Nathan Bossart wrote:
> > Yeah, after staring at this some more, v1 seems reasonable to proceed with
> > for v19 from an RMT perspective.  I've alerted Melanie and Heikki in case
> > they want to share opinions, too.
>
> Hearing nothing, I have expanded the tests in v1 with more option
> patterns, and applied it down to v19.

I was about to deal with this issue.  Thank you for pushing v1,
I'll take a look at v2 for v20.

------
Regards,
Alexander Korotkov
Supabase






^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-09-02 05:16                       ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-09-02 12:53                         ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
@ 2026-09-03 03:38                           ` Michael Paquier <michael@paquier.xyz>
  2026-09-17 22:57                             ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Michael Paquier @ 2026-09-03 03:38 UTC (permalink / raw)
  To: Alexander Korotkov <aekorotkov@gmail.com>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Sami Imseih <samimseih.pg@gmail.com>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

On Wed, Sep 02, 2026 at 03:53:20PM +0300, Alexander Korotkov wrote:
> I was about to deal with this issue.  Thank you for pushing v1,

No problem.

> I'll take a look at v2 for v20.

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.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-09-02 05:16                       ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-09-02 12:53                         ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
  2026-09-03 03:38                           ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
@ 2026-09-17 22:57                             ` Alexander Korotkov <aekorotkov@gmail.com>
  2026-09-25 16:48                               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  0 siblings, 1 reply; 19+ messages in thread

From: Alexander Korotkov @ 2026-09-17 22:57 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Nathan Bossart <nathandbossart@gmail.com>; Sami Imseih <samimseih.pg@gmail.com>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

Hi!

On Thu, Sep 3, 2026 at 6:38 AM Michael Paquier <michael@paquier.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

Attachments:

v3-0001-Jumble-the-WAIT-option-list-by-meaning-not-by-spe.patch (application/octet-stream, 9.2K) download From e879139e9fcea6e9764fbe4af5553257949bcb65 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov <akorotkov@postgresql.org> Date: Fri, 18 Sep 2026 00:08:02 +0300 Subject: [PATCH v3] Jumble the WAIT option list by meaning, not by spelling The LSN target has been normalized since 447aae13b03 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_stat_statements/expected/utility.out | 37 ++++++++++-- contrib/pg_stat_statements/sql/utility.sql | 7 +++ src/backend/nodes/makefuncs.c | 2 + src/backend/nodes/queryjumblefuncs.c | 60 +++++++++++++++++++ src/backend/parser/gram.y | 1 + src/include/nodes/parsenodes.h | 3 +- 6 files changed, 105 insertions(+), 5 deletions(-) diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_stat_statements/expected/utility.out index 0762adbe94a..4d09836ae66 100644 --- a/contrib/pg_stat_statements/expected/utility.out +++ b/contrib/pg_stat_statements/expected/utility.out @@ -744,15 +744,44 @@ WAIT FOR LSN '0/0' WITH (MODE 'primary_flush', TIMEOUT 1); success (1 row) +-- TIMEOUT is a value: these join the entry above. The order the options +-- are written in does not matter either. +WAIT FOR LSN '0/0' WITH (MODE 'primary_flush', TIMEOUT 2); + status +--------- + success +(1 row) + +WAIT FOR LSN '0/0' WITH (TIMEOUT 3, MODE 'primary_flush'); + status +--------- + success +(1 row) + +-- MODE says what to wait for, so each mode gets its own entry. +WAIT FOR LSN '0/0' WITH (MODE 'standby_replay', TIMEOUT 1, NO_THROW); + status +----------------- + not in recovery +(1 row) + +WAIT FOR LSN '0/0' WITH (MODE 'standby_write', TIMEOUT 1, NO_THROW); + status +----------------- + not in recovery +(1 row) + SELECT calls, rows, query FROM pg_stat_statements WHERE query LIKE 'WAIT FOR LSN%' ORDER BY query COLLATE "C"; - calls | rows | query --------+------+-------------------------------------------------------- + calls | rows | query +-------+------+-------------------------------------------------------------------- 2 | 0 | WAIT FOR LSN $1 WITH (MODE 'primary_flush') 1 | 0 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', NO_THROW) - 1 | 0 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', TIMEOUT 1) -(3 rows) + 3 | 0 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', TIMEOUT $2) + 1 | 0 | WAIT FOR LSN $1 WITH (MODE 'standby_replay', TIMEOUT $2, NO_THROW) + 1 | 0 | WAIT FOR LSN $1 WITH (MODE 'standby_write', TIMEOUT $2, NO_THROW) +(5 rows) SELECT pg_stat_statements_reset() IS NOT NULL AS t; t diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_statements/sql/utility.sql index b159c1de1aa..abf64845e9f 100644 --- a/contrib/pg_stat_statements/sql/utility.sql +++ b/contrib/pg_stat_statements/sql/utility.sql @@ -370,6 +370,13 @@ WAIT FOR LSN '0/0' WITH (MODE 'primary_flush'); WAIT FOR LSN '0/1' WITH (MODE 'primary_flush'); WAIT FOR LSN '0/0' WITH (MODE 'primary_flush', NO_THROW); WAIT FOR LSN '0/0' WITH (MODE 'primary_flush', TIMEOUT 1); +-- TIMEOUT is a value: these join the entry above. The order the options +-- are written in does not matter either. +WAIT FOR LSN '0/0' WITH (MODE 'primary_flush', TIMEOUT 2); +WAIT FOR LSN '0/0' WITH (TIMEOUT 3, MODE 'primary_flush'); +-- MODE says what to wait for, so each mode gets its own entry. +WAIT FOR LSN '0/0' WITH (MODE 'standby_replay', TIMEOUT 1, NO_THROW); +WAIT FOR LSN '0/0' WITH (MODE 'standby_write', TIMEOUT 1, NO_THROW); SELECT calls, rows, query FROM pg_stat_statements WHERE query LIKE 'WAIT FOR LSN%' ORDER BY query COLLATE "C"; diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index cdc02b274ff..628f4bb0a48 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -643,6 +643,7 @@ makeDefElem(char *name, Node *arg, int location) res->arg = arg; res->defaction = DEFELEM_UNSPEC; res->location = location; + res->arg_location = -1; return res; } @@ -662,6 +663,7 @@ makeDefElemExtended(char *nameSpace, char *name, Node *arg, res->arg = arg; res->defaction = defaction; res->location = location; + res->arg_location = -1; return res; } diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index 094d2872644..f6e47e08e87 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -79,6 +79,9 @@ static void _jumbleVariableSetStmt(JumbleState *jstate, Node *node); static void _jumbleRangeTblEntry_eref(JumbleState *jstate, RangeTblEntry *rte, Alias *expr); +static void _jumbleWaitStmt_options(JumbleState *jstate, + WaitStmt *expr, + List *options); /* * Given a possibly multi-statement source string, confine our attention to the @@ -774,6 +777,63 @@ _jumbleRangeTblEntry_eref(JumbleState *jstate, JUMBLE_STRING(aliasname); } +/* + * Custom query jumble function for WaitStmt.options. + * + * The WITH clause accepts each option at most once, and the order the options + * are written in does not change what the command does. Jumble the options we + * know in a fixed order, so that a wait written as "WITH (mode 'm', timeout + * 't')" and one written as "WITH (timeout 't', mode 'm')" land in the same + * entry. + * + * TIMEOUT only bounds how long the command may wait, so it is recorded as a + * constant and normalized away; waits differing only in their timeout are + * counted together. MODE and NO_THROW choose what the command does, so their + * values are jumbled as given. An unrecognized option fails at execution + * time, but jumble it too, so that distinct failures do not collide. + */ +static void +_jumbleWaitStmt_options(JumbleState *jstate, WaitStmt *expr, List *options) +{ + static const char *const knownOptions[] = {"mode", "no_throw", "timeout"}; + ListCell *lc; + + for (int i = 0; i < lengthof(knownOptions); i++) + { + foreach(lc, options) + { + DefElem *defel = lfirst_node(DefElem, lc); + + if (strcmp(defel->defname, knownOptions[i]) != 0) + continue; + + AppendJumble(jstate, (const unsigned char *) defel->defname, + strlen(defel->defname) + 1); + + if (strcmp(defel->defname, "timeout") == 0) + RecordConstLocation(jstate, false, defel->arg_location, -1); + else + _jumbleNode(jstate, defel->arg); + } + } + + foreach(lc, options) + { + DefElem *defel = lfirst_node(DefElem, lc); + bool known = false; + + for (int i = 0; i < lengthof(knownOptions); i++) + known = known || strcmp(defel->defname, knownOptions[i]) == 0; + + if (!known) + { + AppendJumble(jstate, (const unsigned char *) defel->defname, + strlen(defel->defname) + 1); + _jumbleNode(jstate, defel->arg); + } + } +} + /* * CompLocation: comparator for qsorting LocationLen structs by location */ diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 0563453fe24..a8bfc6fa9f6 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -1187,6 +1187,7 @@ utility_option_elem: utility_option_name utility_option_arg { $$ = makeDefElem($1, $2, @1); + $$->arg_location = @2; } ; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 0debcd193ab..43d2eff26fa 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -848,6 +848,7 @@ typedef struct DefElem * TypeName */ DefElemAction defaction; /* unspecified action, or SET/ADD/DROP */ ParseLoc location; /* token location, or -1 if unknown */ + ParseLoc arg_location; /* location of arg, or -1 if unknown */ } DefElem; /* @@ -4450,7 +4451,7 @@ typedef struct WaitStmt /* LSN string from grammar */ char *lsn_literal pg_node_attr(query_jumble_ignore); /* List of DefElem nodes */ - List *options; + List *options pg_node_attr(custom_query_jumble); /* token location, or -1 if unknown */ ParseLoc lsn_location pg_node_attr(query_jumble_location); } WaitStmt; -- 2.55.0
^ permalink raw reply [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 01:02   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-30 21:34     ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
  2026-08-30 22:27       ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 02:43         ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 02:56           ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 07:38             ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-08-31 12:20               ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 14:34                 ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-08-31 15:08                   ` Re: WAIT FOR command should do some query jumbling Sami Imseih <samimseih.pg@gmail.com>
  2026-08-31 16:28                     ` Re: WAIT FOR command should do some query jumbling Nathan Bossart <nathandbossart@gmail.com>
  2026-09-02 05:16                       ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-09-02 12:53                         ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
  2026-09-03 03:38                           ` Re: WAIT FOR command should do some query jumbling Michael Paquier <michael@paquier.xyz>
  2026-09-17 22:57                             ` Re: WAIT FOR command should do some query jumbling Alexander Korotkov <aekorotkov@gmail.com>
@ 2026-09-25 16:48                               ` Sami Imseih <samimseih.pg@gmail.com>
  0 siblings, 0 replies; 19+ messages in thread

From: Sami Imseih @ 2026-09-25 16:48 UTC (permalink / raw)
  To: Alexander Korotkov <aekorotkov@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Nathan Bossart <nathandbossart@gmail.com>; sirisha chamarthi <sirichamarthi22@gmail.com>; Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

Hi Alexander,

> Two things today: waits differing only in the timeout get an entry
> each,

I agree this is not ideal, and it's the point I raised earlier.

> and so does the same wait with its options written in another
> order.

I am not sure we should add the additional complexity in the custom
jumble to deal with this. I don't anticipate this will be a problem in
the real world. Scripts and drivers will use the same order. Also we
don't really guarantee that in other commands:

```
VACUUM (ANALYZE, VERBOSE) and VACUUM (VERBOSE, ANALYZE)
```

give different queryIds, and the same is true of COPY and every other
command taking an option list.

If we want option order to not affect the queryId, I think we should
teach jumbling to do this for all commands that take options; the
consumers of utility_option_list and copy_generic_opt_list, and
probably some other places.

So my preference is to deal with the TIMEOUT jumbling only, and
keep the ordering aspect out of this for now.

Maybe others have a different opinion.

--
Sami Imseih
Amazon Web Services (AWS)






^ permalink  raw  reply  [nested|flat] 19+ messages in thread

* Re: WAIT FOR command should do some query jumbling
  2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
  2026-08-28 23:06 ` Re: WAIT FOR command should do some query jumbling sirisha chamarthi <sirichamarthi22@gmail.com>
@ 2026-08-30 19:12   ` Rithvika Devisetti <devisettirithvika@gmail.com>
  1 sibling, 0 replies; 19+ messages in thread

From: Rithvika Devisetti @ 2026-08-30 19:12 UTC (permalink / raw)
  To: sirisha chamarthi <sirichamarthi22@gmail.com>; +Cc: Peter Eisentraut <peter@eisentraut.org>; pgsql-hackers; Alexander Korotkov <akorotkov@postgresql.org>

Hello,

Thanks for the patch. I tested it on with a
clean meson build (cassert enabled). It applies cleanly to master
(92819e57945) and does what it says:

  WAIT FOR LSN '0/0' WITH (MODE 'primary_flush');
  WAIT FOR LSN '0/1' WITH (MODE 'primary_flush');
  WAIT FOR LSN '0/2' WITH (MODE 'primary_flush');

  SELECT calls, query FROM pg_stat_statements WHERE query LIKE 'WAIT FOR%';
   calls |                    query
  -------+---------------------------------------------
       3 | WAIT FOR LSN $1 WITH (MODE 'primary_flush')

Same result with real LSNs from pg_current_wal_lsn(), and the queryid is
stable across resets. Jumbling of other statements is unaffected.

Full test suite passes: 362 OK, 0 failures (the 40 skips are all
PG_TEST_EXTRA opt-ins). No new compiler warnings from the patched files.

One question: the LSN is normalized, but option values still aren't.
Varying TIMEOUT produces separate entries:

   calls |                           query
  -------+-----------------------------------------------------------
       1 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', TIMEOUT 1000)
       1 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', TIMEOUT 2000)
       1 | WAIT FOR LSN $1 WITH (MODE 'primary_flush', TIMEOUT 3000)

A client computing a dynamic timeout (remaining budget, backoff) would
still spam pg_stat_statements, which seems close to the original
complaint. I realize DefElem isn't jumble-annotated and this is
consistent with other utility statements, so it may be out of scope
here, but wanted to raise it in case TIMEOUT is expected to vary in
practice while MODE isn't.

Regards,
Rithvika Devisetti

On Fri, Aug 28, 2026 at 4:07 PM sirisha chamarthi <sirichamarthi22@gmail.com>
wrote:

> Hi Peter,
>
> On Fri, Aug 28, 2026 at 2:48 PM Peter Eisentraut <peter@eisentraut.org>
> wrote:
>
>> Right now, WAIT FOR commands are recorded literally in
>> pg_stat_statements.  I think the actual LSN value should be replaced by
>> some placeholder, like
>>
>> WAIT FOR LSN $1
>>
>> Otherwise, a client library or framework that runs this command
>> repeatedly would needlessly spam pg_stat_statements.
>>
>> The query jumbling facilities should be used to handle this.
>>
>
> +1 to your suggestion. Please find the attached patch to address this
> issue.
>
> Regards,
> Sirisha
>
>

^ permalink  raw  reply  [nested|flat] 19+ messages in thread


end of thread, other threads:[~2026-09-25 16:48 UTC | newest]

Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-28 21:48 WAIT FOR command should do some query jumbling Peter Eisentraut <peter@eisentraut.org>
2026-08-28 23:06 ` sirisha chamarthi <sirichamarthi22@gmail.com>
2026-08-30 01:02   ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-30 20:35     ` Rithvika Devisetti <devisettirithvika@gmail.com>
2026-08-30 21:34     ` sirisha chamarthi <sirichamarthi22@gmail.com>
2026-08-30 22:27       ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-31 02:43         ` Michael Paquier <michael@paquier.xyz>
2026-08-31 02:56           ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-31 07:38             ` Michael Paquier <michael@paquier.xyz>
2026-08-31 12:20               ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-31 14:34                 ` Nathan Bossart <nathandbossart@gmail.com>
2026-08-31 15:08                   ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-31 16:28                     ` Nathan Bossart <nathandbossart@gmail.com>
2026-09-02 05:16                       ` Michael Paquier <michael@paquier.xyz>
2026-09-02 12:53                         ` Alexander Korotkov <aekorotkov@gmail.com>
2026-09-03 03:38                           ` Michael Paquier <michael@paquier.xyz>
2026-09-17 22:57                             ` Alexander Korotkov <aekorotkov@gmail.com>
2026-09-25 16:48                               ` Sami Imseih <samimseih.pg@gmail.com>
2026-08-30 19:12   ` Rithvika Devisetti <devisettirithvika@gmail.com>

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