Add pg_clear_extended_stats() master github/master
authorMichael Paquier <[email protected]>
Thu, 15 Jan 2026 23:13:30 +0000 (08:13 +0900)
committerMichael Paquier <[email protected]>
Thu, 15 Jan 2026 23:13:30 +0000 (08:13 +0900)
commitd756fa1019ff6131944ab263a93a14c4e3b68c39
tree5ba3a2fa6b30b36e111eb945d04898d8a56f4280
parentd40fd85187d06f7bd16fb4d0067bad0b1d248718
Add pg_clear_extended_stats()

This function is able to clear the data associated to an extended
statistics object, making things so as the object looks as
newly-created.

The caller of this function needs the following arguments for the
extended stats to clear:
- The name of the relation.
- The schema name of the relation.
- The name of the extended stats object.
- The schema name of the extended stats object.
- If the stats are inherited or not.

The first two parameters are especially important to ensure a consistent
lookup and ACL checks for the relation on which is based the extended
stats object that will be cleared, relying first on a RangeVar lookup
where permissions are checked without locking a relation, critical to
prevent denial-of-service attacks when using this kind of function (see
also 688dc6299a5b for a similar concern).  The third to fifth arguments
give a way to target the extended stats records to clear.

This has been extracted from a larger patch by the same author, for a
piece which is again useful on its own.  I have rewritten large portions
of it.  The tests have been extended while discussing this piece,
resulting on what this commit includes.  The intention behind this
feature is to add support for the import of extended statistics across
dumps and upgrades, this change building one piece that we will be able
to rely on for the rest of the changes.

Bump catalog version.

Author: Corey Huinker <[email protected]>
Co-authored-by: Michael Paquier <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com
doc/src/sgml/func/func-admin.sgml
src/backend/statistics/Makefile
src/backend/statistics/extended_stats_funcs.c [new file with mode: 0644]
src/backend/statistics/meson.build
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/stats_import.out
src/test/regress/sql/stats_import.sql