From 38378699f57370e2a32c0a1c7d83194570c362ca Mon Sep 17 00:00:00 2001 From: Zhong ShiHao Date: Thu, 27 Aug 2026 22:15:05 -0400 Subject: [PATCH v1] Add test coverage for pg_clear_attribute_stats() null arguments pg_clear_attribute_stats() is not strict and validates its four required arguments itself, but stats_import only ever called it on its success path. That gap let the names in cleararginfo[] stay wrong until 11ed011ae22, where both the schemaname and the relname slot said "relation". Add a case for each required argument. The checks run before the relation lookup, so the expected output does not depend on the state of the cluster. --- src/test/regress/expected/stats_import.out | 33 ++++++++++++++++++++++ src/test/regress/sql/stats_import.sql | 33 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/test/regress/expected/stats_import.out b/src/test/regress/expected/stats_import.out index f2ccb80cf62..af6748e0040 100644 --- a/src/test/regress/expected/stats_import.out +++ b/src/test/regress/expected/stats_import.out @@ -1538,6 +1538,39 @@ AND attname = 'arange'; 0 (1 row) +-- +-- pg_clear_attribute_stats() is not strict, so it checks its required +-- arguments itself. Verify that each one is reported under its own +-- SQL-visible name. +-- +-- error: schemaname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => NULL, + relname => 'test', + attname => 'arange', + inherited => false); +ERROR: argument "schemaname" must not be null +-- error: relname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => NULL, + attname => 'arange', + inherited => false); +ERROR: argument "relname" must not be null +-- error: attname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => 'test', + attname => NULL, + inherited => false); +ERROR: argument "attname" must not be null +-- error: inherited null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => 'test', + attname => 'arange', + inherited => NULL); +ERROR: argument "inherited" must not be null -- temp tables CREATE TEMP TABLE stats_temp(i int); SELECT pg_restore_relation_stats( diff --git a/src/test/regress/sql/stats_import.sql b/src/test/regress/sql/stats_import.sql index 650ce324c7e..13655330783 100644 --- a/src/test/regress/sql/stats_import.sql +++ b/src/test/regress/sql/stats_import.sql @@ -1150,6 +1150,39 @@ AND tablename = 'test' AND inherited = false AND attname = 'arange'; +-- +-- pg_clear_attribute_stats() is not strict, so it checks its required +-- arguments itself. Verify that each one is reported under its own +-- SQL-visible name. +-- +-- error: schemaname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => NULL, + relname => 'test', + attname => 'arange', + inherited => false); + +-- error: relname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => NULL, + attname => 'arange', + inherited => false); + +-- error: attname null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => 'test', + attname => NULL, + inherited => false); + +-- error: inherited null +SELECT pg_catalog.pg_clear_attribute_stats( + schemaname => 'stats_import', + relname => 'test', + attname => 'arange', + inherited => NULL); + -- temp tables CREATE TEMP TABLE stats_temp(i int); SELECT pg_restore_relation_stats( -- 2.37.1 (Apple Git-137.1)