Redundant headers in pg_stat_statements
Thread notes
1 note#refactor
hackorum-bot#refactor
@global #refactor
Hi, hackers!
I accidentially found that some headers in pg_stat_statements are
redundant.
A small patch with removed headers is attached.
Kind regards,
Postgres Professional: http://www.postgrespro.com
Hi,
I applied your patch and it compiles today.
However, three of the four removed headers are not actually unused. The
file still calls functions
declared in them directly, and only keeps compiling because some other
still-included header
happens to drag them back in transitively.
$ pwd
pg20/contrib/pg_stat_statements
$ make clean
$ make > a.compile
$ make install > a.install
$ make installcheck
echo "# +++ regress install-check in contrib/pg_stat_statements +++" &&
../../src/test/regress/pg_regress --inputdir=.
--bindir='/home/vaibhav/work/workspace/pg/pg20/db/bin' --temp-config
../../contrib/pg_stat_statements/pg_stat_statements.conf
--dbname=contrib_regression select dml cursors utility level_tracking
planning user_activity wal entry_timestamp privileges extended parallel
plancache squashing cleanup oldextversions
# +++ regress install-check in contrib/pg_stat_statements +++
# using postmaster on Unix socket, default port
ok 1 - select 78 ms
ok 2 - dml 20 ms
ok 3 - cursors 11 ms
ok 4 - utility 86 ms
ok 5 - level_tracking 74 ms
ok 6 - planning 9 ms
ok 7 - user_activity 11 ms
ok 8 - wal 10 ms
ok 9 - entry_timestamp 11 ms
ok 10 - privileges 13 ms
ok 11 - extended 14 ms
ok 12 - parallel 15 ms
ok 13 - plancache 17 ms
ok 14 - squashing 52 ms
ok 15 - cleanup 6 ms
ok 16 - oldextversions 59 ms
1..16
# All 16 tests passed.
echo "# +++ tap install-check in contrib/pg_stat_statements +++" && rm -rf
'/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements'/tmp_check
&& /usr/bin/mkdir -p
'/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements'/tmp_check
&& cd . &&
TESTLOGDIR='/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements/tmp_check/log'
TESTDATADIR='/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements/tmp_check'
PATH="/home/vaibhav/work/workspace/pg/pg20/db/bin:/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements:$PATH"
PGPORT='65520'
top_builddir='/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements/../..'
PG_REGRESS='/home/vaibhav/work/workspace/pg/pg20/contrib/pg_stat_statements/../../src/test/regress/pg_regress'
share_contrib_dir='/home/vaibhav/work/workspace/pg/pg20/db/share/postgresql/extension'
/usr/bin/prove -I ../../src/test/perl/ -I . t/*.pl
# +++ tap install-check in contrib/pg_stat_statements +++
t/010_restart.pl .. ok
All tests successful.
Files=1, Tests=3, 2 wallclock secs ( 0.01 usr 0.00 sys + 0.68 cusr 0.10
csys = 0.79 CPU)
Result: PASS
*executor/instrument.h*
Still used directly in the file: BufferUsage, WalUsage, instr_time — used
as function params/locals in pgss_store() and the
ExecutorRun hook
Why it still compiles: Only because jit/jit.h (still included) includes it
for its own JitInstrumentation needs
────────────────────────────────────────
*miscadmin.h*
Still used directly in the file: IsParallelWorker(), IsUnderPostmaster,
MyDatabaseId
Why it still compiles: Only because pgstat.h → utils/backend_status.h
includes it, literally commented /* for BackendType */
in that header i.e. for backend_status.h's own use, not as a re-export
────────────────────────────────────────
*nodes/queryjumble.h*
Still used directly in the file: JumbleState (6 uses: hook signature,
pgss_store(), etc.)
Why it still compiles: Only because parser/analyze.h (still included)
includes it — this pairing is a bit more natural since
that's where the post_parse_analyze_hook signature needing JumbleState
lives, but it's still an indirect dependency
────────────────────────────────────────
*utils/memutils.h*
Still used directly in the file: Nothing. no
MemoryContext/CurrentMemoryContext/etc. symbols found anywhere in the file
Why it still compiles: Genuinely safe to remove
Regards,
Vaibhav Dalvi
EnterpriseDB
On Mon, Sep 14, 2026 at 4:44 PM <m.litsarev@postgrespro.ru> wrote:
Show quoted text
Hi, hackers!
I accidentially found that some headers in pg_stat_statements are
redundant.
A small patch with removed headers is attached.Kind regards,
Postgres Professional: http://www.postgrespro.com
On 2026-Sep-14, m.litsarev@postgrespro.ru wrote:
Hi, hackers!
I accidentially found that some headers in pg_stat_statements are redundant.
A small patch with removed headers is attached.
Hi, I'm not sure that this achieves a whole lot -- these headers you
remove are indirectly included by some other header, so removing the
direct inclusions has no practical effect. See the inclusion graph for
that file here:
https://doxygen.postgresql.org/pg__stat__statements_8c.html
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Most hackers will be perfectly comfortable conceptualizing users as entropy
sources, so let's move on." (Nathaniel Smith)
https://mail.gnu.org/archive/html/monotone-devel/2007-01/msg00080.html