pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Correct relation size estimate with low fillfactor 2+ messages / 1 participants [nested] [flat]
* pgsql: Correct relation size estimate with low fillfactor @ 2025-02-19 22:54 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2025-02-19 22:54 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Correct relation size estimate with low fillfactor Since commit 29cf61ade3, table_block_relation_estimate_size() considers fillfactor when estimating number of rows in a relation before the first ANALYZE. The formula however did not consider tuples may be larger than available space determined by fillfactor, ending with density 0. This ultimately means the relation was estimated to contain a single row. The executor however places at least one tuple per page, even with very low fillfactor values, so the density should be at least 1. Fixed by clamping the density estimate using clamp_row_est(). Reported by Heikki Linnakangas. Fix by me, with regression test inspired by example provided by Heikki. Backpatch to 17, where the issue was introduced. Reported-by: Heikki Linnakangas Backpatch-through: 17 Discussion: https://postgr.es/m/2bf9d973-7789-4937-a7ca-0af9fb49c71e@iki.fi Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/9ba7bcc894f1cafb0793a3a62658bd91db1dbecf Modified Files -------------- src/backend/access/table/tableam.c | 3 +++ src/test/regress/expected/stats.out | 17 +++++++++++++++++ src/test/regress/sql/stats.sql | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Correct relation size estimate with low fillfactor @ 2025-02-19 22:54 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2025-02-19 22:54 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Correct relation size estimate with low fillfactor Since commit 29cf61ade3, table_block_relation_estimate_size() considers fillfactor when estimating number of rows in a relation before the first ANALYZE. The formula however did not consider tuples may be larger than available space determined by fillfactor, ending with density 0. This ultimately means the relation was estimated to contain a single row. The executor however places at least one tuple per page, even with very low fillfactor values, so the density should be at least 1. Fixed by clamping the density estimate using clamp_row_est(). Reported by Heikki Linnakangas. Fix by me, with regression test inspired by example provided by Heikki. Backpatch to 17, where the issue was introduced. Reported-by: Heikki Linnakangas Backpatch-through: 17 Discussion: https://postgr.es/m/2bf9d973-7789-4937-a7ca-0af9fb49c71e@iki.fi Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/587b6aa3f3cea5d30e65317c34d0cae288edaa6d Modified Files -------------- src/backend/access/table/tableam.c | 3 +++ src/test/regress/expected/stats.out | 17 +++++++++++++++++ src/test/regress/sql/stats.sql | 16 ++++++++++++++++ 3 files changed, 36 insertions(+) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2025-02-19 22:54 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2025-02-19 22:54 pgsql: Correct relation size estimate with low fillfactor Tomas Vondra <tomas.vondra@postgresql.org> 2025-02-19 22:54 pgsql: Correct relation size estimate with low fillfactor Tomas Vondra <tomas.vondra@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox