> 1. Allow relpages to be set to -1 (partitioned tables with partitions have 
> this value after ANALYZE).
> 2. Turn off autovacuum on tables (where possible) if they are going to be the 
> target of pg_set_relation_stats().
> 3. Allow pg_set_relation_stats to continue past an out-of-range detection on 
> one attribute, rather than immediately returning false

Thank you for developing this feature.
If the relpages option contains -1 only for partitioned tables, shouldn't 
pg_set_relation_stats restrict the values that can be
specified by table type? The attached patch limits the value to -1 or more if 
the target
is a partition table, and 0 or more otherwise.
Changing relpages to -1 on a non-partitioned table seems to significantly 
change the execution plan.

---
postgres=> EXPLAIN (COSTS OFF) SELECT * FROM data1 WHERE c1=1000;
              QUERY PLAN
--------------------------------------
Index Scan using data1_pkey on data1
   Index Cond: (c1 = 1000)
(2 rows)

postgres=> SELECT pg_set_relation_stats('data1', relpages=>-1);
pg_set_relation_stats
-----------------------
t
(1 row)

postgres=> EXPLAIN (COSTS OFF) SELECT * FROM data1 WHERE c1=1000;
              QUERY PLAN
---------------------------------------
Bitmap Heap Scan on data1
   Recheck Cond: (c1 = 1000)
   ->  Bitmap Index Scan on data1_pkey
         Index Cond: (c1 = 1000)
(4 rows)
---

Regards,
Noriyoshi Shinoda

From: Corey Huinker <corey.huin...@gmail.com>
Sent: Saturday, October 19, 2024 10:00 AM
To: Jeff Davis <pg...@j-davis.com>
Cc: Shinoda, Noriyoshi (SXD Japan FSIP) <noriyoshi.shin...@hpe.com>; jian he 
<jian.universal...@gmail.com>; Matthias van de Meent 
<boekewurm+postg...@gmail.com>; Bruce Momjian <br...@momjian.us>; Tom Lane 
<t...@sss.pgh.pa.us>; Nathan Bossart <nathandboss...@gmail.com>; Magnus 
Hagander <mag...@hagander.net>; Stephen Frost <sfr...@snowman.net>; Ashutosh 
Bapat <ashutosh.bapat....@gmail.com>; Peter Smith <smithpb2...@gmail.com>; 
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; alvhe...@alvh.no-ip.org
Subject: Re: Statistics Import and Export



Patch that allows relation_statistics_update to continue after one failed stat 
(0001) attached, along with bool->void change (0002).

Once more, with feeling:

Attachment: pg_set_relation_stats_patch_v1.diff
Description: pg_set_relation_stats_patch_v1.diff

Reply via email to