pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Show values of SET statements as constants in pg_stat_statements
3+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2024-09-30 4c7cd07aa6  Bump catalog version for change in VariableSetStmt
* pgsql: Show values of SET statements as constants in pg_stat_statements
@ 2024-09-30 05:02 Michael Paquier <michael@paquier.xyz>
  2024-09-30 05:16 ` Re: pgsql: Show values of SET statements as constants in pg_stat_statements Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Michael Paquier @ 2024-09-30 05:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Show values of SET statements as constants in pg_stat_statements

This is a continuation of work like 11c34b342bd7, done to reduce the
bloat of pg_stat_statements by applying more normalization to query
entries.  This commit is able to detect and normalize values in
VariableSetStmt, resulting in:
SET conf_param = $1

Compared to other parse nodes, VariableSetStmt is embedded in much more
places in the parser, impacting many query patterns in
pg_stat_statements.  A custom jumble function is used, with an extra
field in the node to decide if arguments should be included in the
jumbling or not, a location field being not enough for this purpose.
This approach allows for a finer tuning.

Clauses relying on one or more keywords are not normalized, for example:
* DEFAULT
* FROM CURRENT
* List of keywords.  SET SESSION CHARACTERISTICS AS TRANSACTION,
where it is critical to differentiate different sets of options, is a
good example of why normalization should not happen.

Some queries use VariableSetStmt for some subclauses with SET, that also
have their values normalized:
- ALTER DATABASE
- ALTER ROLE
- ALTER SYSTEM
- CREATE/ALTER FUNCTION

ba90eac7a995 has added test coverage for most of the existing SET
patterns.  The expected output of these tests shows the difference this
commit creates.  Normalization could be perhaps applied to more portions
of the grammar but what is done here is conservative, and good enough as
a starting point.

Author: Greg Sabino Mullane, Michael Paquier
Discussion: https://postgr.es/m/36e5bffe-e989-194f-85c8-06e7bc88e6f7@amazon.com
Discussion: https://postgr.es/m/B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com
Discussion: https://postgr.es/m/CAKAnmmJtJY2jzQN91=2QAD2eAJAA-Per61eyO48-TyxEg-q0Rg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/dc68515968e80d75f8106d0df05da346be537628

Modified Files
--------------
contrib/pg_stat_statements/expected/dml.out        |  2 +-
.../pg_stat_statements/expected/level_tracking.out |  2 +-
contrib/pg_stat_statements/expected/utility.out    | 20 +++++++-----------
contrib/pg_stat_statements/expected/wal.out        |  2 +-
src/backend/nodes/queryjumblefuncs.c               | 19 +++++++++++++++++
src/backend/parser/gram.y                          | 24 ++++++++++++++++++++++
src/include/nodes/parsenodes.h                     | 21 ++++++++++++++++---
7 files changed, 71 insertions(+), 19 deletions(-)



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

* Re: pgsql: Show values of SET statements as constants in pg_stat_statements
  2024-09-30 05:02 pgsql: Show values of SET statements as constants in pg_stat_statements Michael Paquier <michael@paquier.xyz>
@ 2024-09-30 05:16 ` Tom Lane <tgl@sss.pgh.pa.us>
  2024-09-30 05:27   ` Re: pgsql: Show values of SET statements as constants in pg_stat_statements Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2024-09-30 05:16 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: pgsql-committers@lists.postgresql.org

Michael Paquier <michael@paquier.xyz> writes:
> Show values of SET statements as constants in pg_stat_statements

Shouldn't this have included a catversion bump?  The parsenodes.h
change would for example break new-style SQL functions that include
a SET command.  Probably a narrow use-case, but still.

			regards, tom lane





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

* Re: pgsql: Show values of SET statements as constants in pg_stat_statements
  2024-09-30 05:02 pgsql: Show values of SET statements as constants in pg_stat_statements Michael Paquier <michael@paquier.xyz>
  2024-09-30 05:16 ` Re: pgsql: Show values of SET statements as constants in pg_stat_statements Tom Lane <tgl@sss.pgh.pa.us>
@ 2024-09-30 05:27   ` Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2024-09-30 05:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers@lists.postgresql.org

On Mon, Sep 30, 2024 at 01:16:47AM -0400, Tom Lane wrote:
> Shouldn't this have included a catversion bump?  The parsenodes.h
> change would for example break new-style SQL functions that include
> a SET command.  Probably a narrow use-case, but still.

Hmm, yeah.  I was wondering if I needed a bump, but forgot about that.
Thanks.
--
Michael

Attachments:

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

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


end of thread, other threads:[~2024-09-30 05:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-09-30 05:02 pgsql: Show values of SET statements as constants in pg_stat_statements Michael Paquier <michael@paquier.xyz>
2024-09-30 05:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2024-09-30 05:27   ` Michael Paquier <michael@paquier.xyz>

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