pgsql: Add pg_clear_extended_stats()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add pg_clear_extended_stats()
Date: 2026-01-15 23:15:26
Message-ID: E1vgWYn-000hYL-39@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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 <corey(dot)huinker(at)gmail(dot)com>
Co-authored-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d756fa1019ff6131944ab263a93a14c4e3b68c39

Modified Files
--------------
doc/src/sgml/func/func-admin.sgml | 29 ++++
src/backend/statistics/Makefile | 1 +
src/backend/statistics/extended_stats_funcs.c | 232 ++++++++++++++++++++++++++
src/backend/statistics/meson.build | 1 +
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 7 +
src/test/regress/expected/stats_import.out | 210 +++++++++++++++++++++++
src/test/regress/sql/stats_import.sql | 137 +++++++++++++++
8 files changed, 618 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2026-01-16 03:13:21 pgsql: Fix stability issue with new TAP test of pg_createsubscriber
Previous Message Andres Freund 2026-01-15 19:59:29 pgsql: pgindent fix for 8077649907d