From: Julien Rouhaud <rjuju123@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Subject: pg_stat_statements oddity with track = all
Date: Wed, 2 Dec 2020 12:05:16 +0800
Message-ID: <20201202040516.GA43757@nol> (raw)
Hi,
Someone raised an interested point recently on pg_stat_kcache extension for
handling nested statements, which also applies to pg_stat_statements.
The root issue is that when pg_stat_statements tracks nested statements,
there's no way to really make sense of the counters, as top level statements
will also account for underlying statements. Using a naive example:
=# CREATE FUNCTION f1() RETURNS VOID AS $$BEGIN PERFORM pg_sleep(5); END; $$ LANGUAGE plpgsql;
CREATE FUNCTION
=# SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------
(1 row)
=# SELECT f1();
f1
----
(1 row)
=# select sum(total_exec_time) from pg_stat_statements;
sum
--------------
10004.403601
(1 row)
It looks like there was 10s total execution time overall all statements, which
doesn't really make sense.
It's of course possible to avoid that using track = top, but tracking all
nested statements is usually quite useful so it could be better to find a way
to better address that problem.
The only idea I have for that is to add a new field to entry key, for instance
is_toplevel. The immediate cons is obviously that it could amplify quite a lot
the number of entries tracked, so people may need to increase
pg_stat_statements.max to avoid slowdown if that makes them reach frequent
entry eviction.
Should we address the problem, and in that case do you see a better way for
that, or should we just document this behavior?
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: rjuju123@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: pg_stat_statements oddity with track = all
In-Reply-To: <20201202040516.GA43757@nol>
* 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