From 6e023ad2bebd534b9ce7ac2697641d1759a8ecf0 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 23 Dec 2023 14:25:26 +0100 Subject: [PATCH v1 4/5] pg_stat_statements: Add coverage for entry_dealloc() This involves creating pg_stat_statements.max entries, then creating even more entries, and checking that the limit is kept and the least used entries are kicked out. --- contrib/pg_stat_statements/Makefile | 2 +- contrib/pg_stat_statements/expected/max.out | 1127 +++++++++++++++++ contrib/pg_stat_statements/meson.build | 1 + .../pg_stat_statements.conf | 2 + contrib/pg_stat_statements/sql/max.sql | 18 + 5 files changed, 1149 insertions(+), 1 deletion(-) create mode 100644 contrib/pg_stat_statements/expected/max.out create mode 100644 contrib/pg_stat_statements/sql/max.sql diff --git a/contrib/pg_stat_statements/Makefile b/contrib/pg_stat_statements/Makefile index aecd1d6a2a..7ee16e8350 100644 --- a/contrib/pg_stat_statements/Makefile +++ b/contrib/pg_stat_statements/Makefile @@ -19,7 +19,7 @@ LDFLAGS_SL += $(filter -lm, $(LIBS)) REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_statements/pg_stat_statements.conf REGRESS = select dml cursors utility level_tracking planning \ - user_activity wal entry_timestamp cleanup oldextversions + user_activity wal entry_timestamp max cleanup oldextversions # Disabled because these tests require "shared_preload_libraries=pg_stat_statements", # which typical installcheck users do not have (e.g. buildfarm clients). NO_INSTALLCHECK = 1 diff --git a/contrib/pg_stat_statements/expected/max.out b/contrib/pg_stat_statements/expected/max.out new file mode 100644 index 0000000000..60750d15c2 --- /dev/null +++ b/contrib/pg_stat_statements/expected/max.out @@ -0,0 +1,1127 @@ +SHOW pg_stat_statements.max; + pg_stat_statements.max +------------------------ + 100 +(1 row) + +SELECT format('create table t%s (a int)', lpad(i::text, 3, '0')) FROM generate_series(1, 101) AS x(i) \gexec +create table t001 (a int) +create table t002 (a int) +create table t003 (a int) +create table t004 (a int) +create table t005 (a int) +create table t006 (a int) +create table t007 (a int) +create table t008 (a int) +create table t009 (a int) +create table t010 (a int) +create table t011 (a int) +create table t012 (a int) +create table t013 (a int) +create table t014 (a int) +create table t015 (a int) +create table t016 (a int) +create table t017 (a int) +create table t018 (a int) +create table t019 (a int) +create table t020 (a int) +create table t021 (a int) +create table t022 (a int) +create table t023 (a int) +create table t024 (a int) +create table t025 (a int) +create table t026 (a int) +create table t027 (a int) +create table t028 (a int) +create table t029 (a int) +create table t030 (a int) +create table t031 (a int) +create table t032 (a int) +create table t033 (a int) +create table t034 (a int) +create table t035 (a int) +create table t036 (a int) +create table t037 (a int) +create table t038 (a int) +create table t039 (a int) +create table t040 (a int) +create table t041 (a int) +create table t042 (a int) +create table t043 (a int) +create table t044 (a int) +create table t045 (a int) +create table t046 (a int) +create table t047 (a int) +create table t048 (a int) +create table t049 (a int) +create table t050 (a int) +create table t051 (a int) +create table t052 (a int) +create table t053 (a int) +create table t054 (a int) +create table t055 (a int) +create table t056 (a int) +create table t057 (a int) +create table t058 (a int) +create table t059 (a int) +create table t060 (a int) +create table t061 (a int) +create table t062 (a int) +create table t063 (a int) +create table t064 (a int) +create table t065 (a int) +create table t066 (a int) +create table t067 (a int) +create table t068 (a int) +create table t069 (a int) +create table t070 (a int) +create table t071 (a int) +create table t072 (a int) +create table t073 (a int) +create table t074 (a int) +create table t075 (a int) +create table t076 (a int) +create table t077 (a int) +create table t078 (a int) +create table t079 (a int) +create table t080 (a int) +create table t081 (a int) +create table t082 (a int) +create table t083 (a int) +create table t084 (a int) +create table t085 (a int) +create table t086 (a int) +create table t087 (a int) +create table t088 (a int) +create table t089 (a int) +create table t090 (a int) +create table t091 (a int) +create table t092 (a int) +create table t093 (a int) +create table t094 (a int) +create table t095 (a int) +create table t096 (a int) +create table t097 (a int) +create table t098 (a int) +create table t099 (a int) +create table t100 (a int) +create table t101 (a int) +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + t +--- + t +(1 row) + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) FROM generate_series(1, 98) AS x(i) \gexec +select * from t001 + a +--- +(0 rows) + +select * from t002 + a +--- +(0 rows) + +select * from t003 + a +--- +(0 rows) + +select * from t004 + a +--- +(0 rows) + +select * from t005 + a +--- +(0 rows) + +select * from t006 + a +--- +(0 rows) + +select * from t007 + a +--- +(0 rows) + +select * from t008 + a +--- +(0 rows) + +select * from t009 + a +--- +(0 rows) + +select * from t010 + a +--- +(0 rows) + +select * from t011 + a +--- +(0 rows) + +select * from t012 + a +--- +(0 rows) + +select * from t013 + a +--- +(0 rows) + +select * from t014 + a +--- +(0 rows) + +select * from t015 + a +--- +(0 rows) + +select * from t016 + a +--- +(0 rows) + +select * from t017 + a +--- +(0 rows) + +select * from t018 + a +--- +(0 rows) + +select * from t019 + a +--- +(0 rows) + +select * from t020 + a +--- +(0 rows) + +select * from t021 + a +--- +(0 rows) + +select * from t022 + a +--- +(0 rows) + +select * from t023 + a +--- +(0 rows) + +select * from t024 + a +--- +(0 rows) + +select * from t025 + a +--- +(0 rows) + +select * from t026 + a +--- +(0 rows) + +select * from t027 + a +--- +(0 rows) + +select * from t028 + a +--- +(0 rows) + +select * from t029 + a +--- +(0 rows) + +select * from t030 + a +--- +(0 rows) + +select * from t031 + a +--- +(0 rows) + +select * from t032 + a +--- +(0 rows) + +select * from t033 + a +--- +(0 rows) + +select * from t034 + a +--- +(0 rows) + +select * from t035 + a +--- +(0 rows) + +select * from t036 + a +--- +(0 rows) + +select * from t037 + a +--- +(0 rows) + +select * from t038 + a +--- +(0 rows) + +select * from t039 + a +--- +(0 rows) + +select * from t040 + a +--- +(0 rows) + +select * from t041 + a +--- +(0 rows) + +select * from t042 + a +--- +(0 rows) + +select * from t043 + a +--- +(0 rows) + +select * from t044 + a +--- +(0 rows) + +select * from t045 + a +--- +(0 rows) + +select * from t046 + a +--- +(0 rows) + +select * from t047 + a +--- +(0 rows) + +select * from t048 + a +--- +(0 rows) + +select * from t049 + a +--- +(0 rows) + +select * from t050 + a +--- +(0 rows) + +select * from t051 + a +--- +(0 rows) + +select * from t052 + a +--- +(0 rows) + +select * from t053 + a +--- +(0 rows) + +select * from t054 + a +--- +(0 rows) + +select * from t055 + a +--- +(0 rows) + +select * from t056 + a +--- +(0 rows) + +select * from t057 + a +--- +(0 rows) + +select * from t058 + a +--- +(0 rows) + +select * from t059 + a +--- +(0 rows) + +select * from t060 + a +--- +(0 rows) + +select * from t061 + a +--- +(0 rows) + +select * from t062 + a +--- +(0 rows) + +select * from t063 + a +--- +(0 rows) + +select * from t064 + a +--- +(0 rows) + +select * from t065 + a +--- +(0 rows) + +select * from t066 + a +--- +(0 rows) + +select * from t067 + a +--- +(0 rows) + +select * from t068 + a +--- +(0 rows) + +select * from t069 + a +--- +(0 rows) + +select * from t070 + a +--- +(0 rows) + +select * from t071 + a +--- +(0 rows) + +select * from t072 + a +--- +(0 rows) + +select * from t073 + a +--- +(0 rows) + +select * from t074 + a +--- +(0 rows) + +select * from t075 + a +--- +(0 rows) + +select * from t076 + a +--- +(0 rows) + +select * from t077 + a +--- +(0 rows) + +select * from t078 + a +--- +(0 rows) + +select * from t079 + a +--- +(0 rows) + +select * from t080 + a +--- +(0 rows) + +select * from t081 + a +--- +(0 rows) + +select * from t082 + a +--- +(0 rows) + +select * from t083 + a +--- +(0 rows) + +select * from t084 + a +--- +(0 rows) + +select * from t085 + a +--- +(0 rows) + +select * from t086 + a +--- +(0 rows) + +select * from t087 + a +--- +(0 rows) + +select * from t088 + a +--- +(0 rows) + +select * from t089 + a +--- +(0 rows) + +select * from t090 + a +--- +(0 rows) + +select * from t091 + a +--- +(0 rows) + +select * from t092 + a +--- +(0 rows) + +select * from t093 + a +--- +(0 rows) + +select * from t094 + a +--- +(0 rows) + +select * from t095 + a +--- +(0 rows) + +select * from t096 + a +--- +(0 rows) + +select * from t097 + a +--- +(0 rows) + +select * from t098 + a +--- +(0 rows) + +SELECT count(*) <= 100 AND count(*) > 0 FROM pg_stat_statements; + ?column? +---------- + t +(1 row) + +SELECT query FROM pg_stat_statements WHERE query LIKE '%t001%' OR query LIKE '%t098%' ORDER BY query; + query +-------------------- + select * from t001 + select * from t098 +(2 rows) + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) from generate_series(2, 98) AS x(i) \gexec +select * from t002 + a +--- +(0 rows) + +select * from t003 + a +--- +(0 rows) + +select * from t004 + a +--- +(0 rows) + +select * from t005 + a +--- +(0 rows) + +select * from t006 + a +--- +(0 rows) + +select * from t007 + a +--- +(0 rows) + +select * from t008 + a +--- +(0 rows) + +select * from t009 + a +--- +(0 rows) + +select * from t010 + a +--- +(0 rows) + +select * from t011 + a +--- +(0 rows) + +select * from t012 + a +--- +(0 rows) + +select * from t013 + a +--- +(0 rows) + +select * from t014 + a +--- +(0 rows) + +select * from t015 + a +--- +(0 rows) + +select * from t016 + a +--- +(0 rows) + +select * from t017 + a +--- +(0 rows) + +select * from t018 + a +--- +(0 rows) + +select * from t019 + a +--- +(0 rows) + +select * from t020 + a +--- +(0 rows) + +select * from t021 + a +--- +(0 rows) + +select * from t022 + a +--- +(0 rows) + +select * from t023 + a +--- +(0 rows) + +select * from t024 + a +--- +(0 rows) + +select * from t025 + a +--- +(0 rows) + +select * from t026 + a +--- +(0 rows) + +select * from t027 + a +--- +(0 rows) + +select * from t028 + a +--- +(0 rows) + +select * from t029 + a +--- +(0 rows) + +select * from t030 + a +--- +(0 rows) + +select * from t031 + a +--- +(0 rows) + +select * from t032 + a +--- +(0 rows) + +select * from t033 + a +--- +(0 rows) + +select * from t034 + a +--- +(0 rows) + +select * from t035 + a +--- +(0 rows) + +select * from t036 + a +--- +(0 rows) + +select * from t037 + a +--- +(0 rows) + +select * from t038 + a +--- +(0 rows) + +select * from t039 + a +--- +(0 rows) + +select * from t040 + a +--- +(0 rows) + +select * from t041 + a +--- +(0 rows) + +select * from t042 + a +--- +(0 rows) + +select * from t043 + a +--- +(0 rows) + +select * from t044 + a +--- +(0 rows) + +select * from t045 + a +--- +(0 rows) + +select * from t046 + a +--- +(0 rows) + +select * from t047 + a +--- +(0 rows) + +select * from t048 + a +--- +(0 rows) + +select * from t049 + a +--- +(0 rows) + +select * from t050 + a +--- +(0 rows) + +select * from t051 + a +--- +(0 rows) + +select * from t052 + a +--- +(0 rows) + +select * from t053 + a +--- +(0 rows) + +select * from t054 + a +--- +(0 rows) + +select * from t055 + a +--- +(0 rows) + +select * from t056 + a +--- +(0 rows) + +select * from t057 + a +--- +(0 rows) + +select * from t058 + a +--- +(0 rows) + +select * from t059 + a +--- +(0 rows) + +select * from t060 + a +--- +(0 rows) + +select * from t061 + a +--- +(0 rows) + +select * from t062 + a +--- +(0 rows) + +select * from t063 + a +--- +(0 rows) + +select * from t064 + a +--- +(0 rows) + +select * from t065 + a +--- +(0 rows) + +select * from t066 + a +--- +(0 rows) + +select * from t067 + a +--- +(0 rows) + +select * from t068 + a +--- +(0 rows) + +select * from t069 + a +--- +(0 rows) + +select * from t070 + a +--- +(0 rows) + +select * from t071 + a +--- +(0 rows) + +select * from t072 + a +--- +(0 rows) + +select * from t073 + a +--- +(0 rows) + +select * from t074 + a +--- +(0 rows) + +select * from t075 + a +--- +(0 rows) + +select * from t076 + a +--- +(0 rows) + +select * from t077 + a +--- +(0 rows) + +select * from t078 + a +--- +(0 rows) + +select * from t079 + a +--- +(0 rows) + +select * from t080 + a +--- +(0 rows) + +select * from t081 + a +--- +(0 rows) + +select * from t082 + a +--- +(0 rows) + +select * from t083 + a +--- +(0 rows) + +select * from t084 + a +--- +(0 rows) + +select * from t085 + a +--- +(0 rows) + +select * from t086 + a +--- +(0 rows) + +select * from t087 + a +--- +(0 rows) + +select * from t088 + a +--- +(0 rows) + +select * from t089 + a +--- +(0 rows) + +select * from t090 + a +--- +(0 rows) + +select * from t091 + a +--- +(0 rows) + +select * from t092 + a +--- +(0 rows) + +select * from t093 + a +--- +(0 rows) + +select * from t094 + a +--- +(0 rows) + +select * from t095 + a +--- +(0 rows) + +select * from t096 + a +--- +(0 rows) + +select * from t097 + a +--- +(0 rows) + +select * from t098 + a +--- +(0 rows) + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) from generate_series(99, 100) AS x(i) \gexec +select * from t099 + a +--- +(0 rows) + +select * from t100 + a +--- +(0 rows) + +SELECT count(*) <= 100 AND count(*) > 0 FROM pg_stat_statements; + ?column? +---------- + t +(1 row) + +-- record for t001 has been kicked out +SELECT query FROM pg_stat_statements WHERE query LIKE '%t001%' ORDER BY query; + query +------- +(0 rows) + diff --git a/contrib/pg_stat_statements/meson.build b/contrib/pg_stat_statements/meson.build index 81fe1eb917..a66acaa5b8 100644 --- a/contrib/pg_stat_statements/meson.build +++ b/contrib/pg_stat_statements/meson.build @@ -50,6 +50,7 @@ tests += { 'user_activity', 'wal', 'entry_timestamp', + 'max', 'cleanup', 'oldextversions', ], diff --git a/contrib/pg_stat_statements/pg_stat_statements.conf b/contrib/pg_stat_statements/pg_stat_statements.conf index 0e900d7119..0119f681d7 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.conf +++ b/contrib/pg_stat_statements/pg_stat_statements.conf @@ -1,2 +1,4 @@ shared_preload_libraries = 'pg_stat_statements' max_prepared_transactions = 5 + +pg_stat_statements.max = 100 diff --git a/contrib/pg_stat_statements/sql/max.sql b/contrib/pg_stat_statements/sql/max.sql new file mode 100644 index 0000000000..ce6a1bd84e --- /dev/null +++ b/contrib/pg_stat_statements/sql/max.sql @@ -0,0 +1,18 @@ +SHOW pg_stat_statements.max; + +SELECT format('create table t%s (a int)', lpad(i::text, 3, '0')) FROM generate_series(1, 101) AS x(i) \gexec + +SELECT pg_stat_statements_reset() IS NOT NULL AS t; + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) FROM generate_series(1, 98) AS x(i) \gexec + +SELECT count(*) <= 100 AND count(*) > 0 FROM pg_stat_statements; +SELECT query FROM pg_stat_statements WHERE query LIKE '%t001%' OR query LIKE '%t098%' ORDER BY query; + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) from generate_series(2, 98) AS x(i) \gexec + +SELECT format('select * from t%s', lpad(i::text, 3, '0')) from generate_series(99, 100) AS x(i) \gexec + +SELECT count(*) <= 100 AND count(*) > 0 FROM pg_stat_statements; +-- record for t001 has been kicked out +SELECT query FROM pg_stat_statements WHERE query LIKE '%t001%' ORDER BY query; -- 2.43.0