Issue fat-fingered in
d756fa1019ff, noticed while doing more review of
the main patch set proposed. I have missed the fact that this can be
triggered by specifying an extended stats object that does not match
with the relation specified and already locked. Like the cases where
an object defined in input is missing, the code is changed to issue a
WARNING instead of a confusing cache lookup failure.
A regression test is added to cover this case.
Discussion: https://postgr.es/m/CADkLM=dpz3KFnqP-dgJ-zvRvtjsa8UZv8wDAQdqho=qN3kX0Zg@mail.gmail.com
* started.
*/
if (stxform->stxrelid != relid)
- elog(ERROR, "cache lookup failed for extended stats %u: found relation %u but expected %u",
- stxform->oid, stxform->stxrelid, relid);
+ {
+ table_close(pg_stext, RowExclusiveLock);
+ ereport(WARNING,
+ errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("could not clear extended statistics object \"%s\".\"%s\": incorrect relation \"%s\".\"%s\" specified",
+ get_namespace_name(nspoid), stxname,
+ relnspname, relname));
+ PG_RETURN_VOID();
+ }
delete_pg_statistic_ext_data(stxform->oid, inherited);
heap_freetuple(tup);
(1 row)
+-- Incorrect relation/extended stats combination
+SELECT pg_clear_extended_stats(schemaname => 'stats_import',
+ relname => 'test',
+ statistics_schemaname => 'stats_import',
+ statistics_name => 'test_stat_clone',
+ inherited => false);
+WARNING: could not clear extended statistics object "stats_import"."test_stat_clone": incorrect relation "stats_import"."test" specified
+ pg_clear_extended_stats
+-------------------------
+
+(1 row)
+
-- Check that records are removed after a valid clear call.
SELECT COUNT(*), e.inherited FROM pg_stats_ext AS e
WHERE e.statistics_schemaname = 'stats_import' AND
statistics_schemaname => 'stats_import',
statistics_name => 'ext_stats_not_exist',
inherited => false);
+-- Incorrect relation/extended stats combination
+SELECT pg_clear_extended_stats(schemaname => 'stats_import',
+ relname => 'test',
+ statistics_schemaname => 'stats_import',
+ statistics_name => 'test_stat_clone',
+ inherited => false);
-- Check that records are removed after a valid clear call.
SELECT COUNT(*), e.inherited FROM pg_stats_ext AS e