pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor tests of pg_stat_statements for planning, utility and l
Date: Mon, 20 Feb 2023 00:29:46 +0000
Message-ID: <E1pTu3u-00204Y-8m@gemulon.postgresql.org> (raw)

Refactor tests of pg_stat_statements for planning, utility and level tracking

pg_stat_statements.sql acts as the main file for all the core tests of
the module, but things have become complicated to follow over the years
as some of the sub-scenarios tested in this file rely on assumptions
that come from completely different areas of it, like a GUC setup or a
relation created previously.  For example, row tracking for CTAS/COPY
was looking at the number of plans, which was not necessary, or level
tracking was mixed with checks on planner counts.

This commit refactors the tests of pg_stat_statements, by moving test
cases out of pg_stat_statements.sql into their own file, as of:
- Planning-related tests in planning.sql, for [re]plan counts and
top-level handling.  These depend on pg_stat_statements.track_planning.
- Utilities in utility.sql (pg_stat_statements.track_utility), that
includes now the tests for:
-- Row tracking for CTAS, CREATE MATERIALIZED VIEW, COPY.
-- Basic utility statements.
-- SET statements.
- Tracking level, depending on pg_stat_statements.track.  This part has
been looking at scenarios with DO blocks, PL functions and SQL
functions.

pg_stat_statements.sql (still named the same for now) still includes
some checks for role-level tracking and WAL generation metrics, that
ought to become independent in the long term for clarity.

While on it, this switches the order of the attributes when querying
pg_stat_statements, the query field becoming last.  This makes much
easier the tracking of changes related to normalization, as queries are
the only variable-length attributes queried (unaligned mode would be one
extra choice, but that reduces the checks on the other fields).

Test scenarios and their results match exactly with what was happening
before this commit in terms of calls, number of plans, number of rows,
cached data or level tracking, so this has no effect on the coverage in
terms of what is produced by the reports in the table
pg_stat_statements.  A follow-up patch will extend more the tests of
pg_stat_statements around utilities, so this split creates a foundation
for this purpose, without complicating more pg_stat_statements.sql.

Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/Y+MRdEq9W9XVa2AB@paquier.xyz

Branch
------
master

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

Modified Files
--------------
contrib/pg_stat_statements/Makefile                |   2 +-
contrib/pg_stat_statements/expected/cleanup.out    |   1 +
.../pg_stat_statements/expected/level_tracking.out | 204 +++++++++++
.../expected/pg_stat_statements.out                | 393 +--------------------
contrib/pg_stat_statements/expected/planning.out   |  88 +++++
contrib/pg_stat_statements/expected/utility.out    | 132 +++++++
contrib/pg_stat_statements/meson.build             |   4 +
contrib/pg_stat_statements/sql/cleanup.sql         |   1 +
contrib/pg_stat_statements/sql/level_tracking.sql  |  99 ++++++
.../pg_stat_statements/sql/pg_stat_statements.sql  | 178 +---------
contrib/pg_stat_statements/sql/planning.sql        |  31 ++
contrib/pg_stat_statements/sql/utility.sql         |  60 ++++
12 files changed, 623 insertions(+), 570 deletions(-)



Message-ID: <E1pTu3u-00204Y-8m@gemulon.postgresql.org>
Permalink:  ../E1pTu3u-00204Y-8m@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pTu3u-00204Y-8m@gemulon.postgresql.org

 · 

reply

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-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Refactor tests of pg_stat_statements for planning, utility and l
  In-Reply-To: <E1pTu3u-00204Y-8m@gemulon.postgresql.org>
  References: <E1pTu3u-00204Y-8m@gemulon.postgresql.org>

* 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