postgres/contrib/pg_stat_statements/sql
Michael Paquier 499edb0974 Track more precisely query locations for nested statements
Previously, a Query generated through the transform phase would have
unset stmt_location, tracking the starting point of a query string.

Extensions relying on the statement location to extract its relevant
parts in the source text string would fallback to use the whole
statement instead, leading to confusing results like in
pg_stat_statements for queries relying on nested queries, like:
- EXPLAIN, with top-level and nested query using the same query string,
and a query ID coming from the nested query when the non-top-level
entry.
- Multi-statements, with only partial portions of queries being
normalized.
- COPY TO with a query, SELECT or DMLs.

This patch improves things by keeping track of the statement locations
and propagate it to Query during transform, allowing PGSS to only show
the relevant part of the query for nested query.  This leads to less
bloat in entries for non-top-level entries, as queries can now be
grouped within the same (toplevel, queryid) duos in pg_stat_statements.
The result gives a stricter one-one mapping between query IDs and its
query strings.

The regression tests introduced in 45e0ba30fc produce differences
reflecting the new logic.

Author: Anthonin Bonnefoy
Reviewed-by: Michael Paquier, Jian He
Discussion: https://postgr.es/m/CAO6_XqqM6S9bQ2qd=75W+yKATwoazxSNhv5sjW06fjGAtHbTUA@mail.gmail.com
2024-10-24 09:29:54 +09:00
..
cleanup.sql Refactor tests of pg_stat_statements for planning, utility and level tracking 2023-02-20 09:28:29 +09:00
cursors.sql Add NOT NULL checking of pg_stat_statements_reset() in tests 2023-11-27 02:52:17 +02:00
dml.sql Add NOT NULL checking of pg_stat_statements_reset() in tests 2023-11-27 02:52:17 +02:00
entry_timestamp.sql Track statement entry timestamp in contrib/pg_stat_statements 2023-11-27 02:52:17 +02:00
extended.sql Add missing query ID reporting in extended query protocol 2024-09-18 09:59:09 +09:00
level_tracking.sql pg_stat_statements: Add tests for nested queries with level tracking 2024-10-22 13:05:51 +09:00
oldextversions.sql pg_stat_statements: Add columns to track parallel worker activity 2024-10-09 08:30:45 +09:00
parallel.sql pg_stat_statements: Add columns to track parallel worker activity 2024-10-09 08:30:45 +09:00
planning.sql Track more precisely query locations for nested statements 2024-10-24 09:29:54 +09:00
privileges.sql pg_stat_statements: Add regression test for privilege handling. 2024-07-24 20:54:51 +09:00
select.sql Improve parser's reporting of statement start locations. 2024-10-22 11:26:05 -04:00
user_activity.sql Add NOT NULL checking of pg_stat_statements_reset() in tests 2023-11-27 02:52:17 +02:00
utility.sql pg_stat_statements: Expand tests for SET statements 2024-09-25 10:04:44 +09:00
wal.sql Add NOT NULL checking of pg_stat_statements_reset() in tests 2023-11-27 02:52:17 +02:00