postgresql/contrib/pg_stat_statements
Tom Lane 56083ff301 pg_stat_statements: fetch stmt location/length before it disappears.
When executing a utility statement, we must fetch everything
we need out of the PlannedStmt data structure before calling
standard_ProcessUtility.  In certain cases (possibly only ROLLBACK
in extended query protocol), that data structure will get freed
during command execution.  The situation is probably often harmless
in production builds, but in debug builds we intentionally overwrite
the freed memory with garbage, leading to picking up garbage values
of statement location and length, typically causing an assertion
failure later in pg_stat_statements.  In non-debug builds, if
something did go wrong it would likely lead to storing garbage
for the query string.

Report and fix by zhaoqigui (with cosmetic adjustments by me).
It's an old problem, so back-patch to all supported versions.

Discussion: https://postgr.es/m/17663-a344fd0675f92128@postgresql.org
Discussion: https://postgr.es/m/1667307420050.56657@hundsun.com
2022-11-01 12:48:01 -04:00
..
expected Show ignored constants as "$N" rather than "?" in pg_stat_statements. 2017-03-27 20:14:36 -04:00
sql Show ignored constants as "$N" rather than "?" in pg_stat_statements. 2017-03-27 20:14:36 -04:00
.gitignore pg_stat_statements: Add .gitignore file for tests 2016-11-13 08:24:43 -05:00
Makefile Revoke pg_stat_statements_reset() permissions 2018-09-25 09:56:57 +09:00
pg_stat_statements--1.0--1.1.sql Fix typo in update scripts for some contrib modules. 2013-07-19 04:13:01 +09:00
pg_stat_statements--1.1--1.2.sql Keep pg_stat_statements' query texts in a file, not in shared memory. 2014-01-27 15:37:54 -05:00
pg_stat_statements--1.2--1.3.sql Add stats for min, max, mean, stddev times to pg_stat_statements. 2015-03-27 15:43:22 -04:00
pg_stat_statements--1.3--1.4.sql Update pg_stat_statements extension for parallel query. 2016-06-10 10:42:01 -04:00
pg_stat_statements--1.4--1.5.sql Default monitoring roles 2017-03-30 14:18:53 -04:00
pg_stat_statements--1.4.sql Update pg_stat_statements extension for parallel query. 2016-06-10 10:42:01 -04:00
pg_stat_statements--1.5--1.6.sql Revoke pg_stat_statements_reset() permissions 2018-09-25 09:56:57 +09:00
pg_stat_statements--unpackaged--1.0.sql Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pg_stat_statements.c pg_stat_statements: fetch stmt location/length before it disappears. 2022-11-01 12:48:01 -04:00
pg_stat_statements.conf Add minimal set of regression tests for pg_stat_statements. 2016-11-12 05:01:48 -08:00
pg_stat_statements.control Revoke pg_stat_statements_reset() permissions 2018-09-25 09:56:57 +09:00