mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
This commit reverts the two following commits: -499edb0974
, track more precisely query locations for nested statements. -06450c7b8c
, a follow-up fix of499edb0974
with query locations. The test introduced in this commit is not reverted. This is proving useful to track a problem that only pgaudit was able to detect. These prove to have issues with the tracking of SELECT statements, when these use multiple parenthesis which is something supported by the grammar. Incorrect location and lengths are causing pg_stat_statements to become confused, failing its job in query normalization with potential out-of-bound writes because the location and the length may not match with what can be handled. A lot of the query patterns discussed when this issue was reported have no test coverage in the main regression test suite, or the recovery test 027_stream_regress.pl would have caught the problems as pg_stat_statements is loaded by the node running the regression tests. A first step would be to improve the test coverage to stress more the query normalization logic. A different portion of this work was done in45e0ba30fc
, with the addition of tests for nested queries. These can be left in the tree. They are useful to track the way inner queries are currently tracked by PGSS with non-top-level entries, and will be useful when reconsidering in the future the work reverted here. Reported-by: Alexander Kozhemyakin <a.kozhemyakin@postgrespro.ru> Discussion: https://postgr.es/m/18947-cdd2668beffe02bf@postgresql.org
32 lines
915 B
SQL
32 lines
915 B
SQL
--
|
|
-- Information related to planning
|
|
--
|
|
|
|
-- These tests require track_planning to be enabled.
|
|
SET pg_stat_statements.track_planning = TRUE;
|
|
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
|
|
|
|
--
|
|
-- [re]plan counting
|
|
--
|
|
CREATE TABLE stats_plan_test ();
|
|
PREPARE prep1 AS SELECT COUNT(*) FROM stats_plan_test;
|
|
EXECUTE prep1;
|
|
EXECUTE prep1;
|
|
EXECUTE prep1;
|
|
ALTER TABLE stats_plan_test ADD COLUMN x int;
|
|
EXECUTE prep1;
|
|
SELECT 42;
|
|
SELECT 42;
|
|
SELECT 42;
|
|
SELECT plans, calls, rows, query FROM pg_stat_statements
|
|
WHERE query NOT LIKE 'PREPARE%' ORDER BY query COLLATE "C";
|
|
-- for the prepared statement we expect at least one replan, but cache
|
|
-- invalidations could force more
|
|
SELECT plans >= 2 AND plans <= calls AS plans_ok, calls, rows, query FROM pg_stat_statements
|
|
WHERE query LIKE 'PREPARE%' ORDER BY query COLLATE "C";
|
|
|
|
-- Cleanup
|
|
DROP TABLE stats_plan_test;
|
|
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
|