From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
---|---|
To: | Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Should heapam_estimate_rel_size consider fillfactor? |
Date: | 2025-01-29 18:56:35 |
Message-ID: | 2bf9d973-7789-4937-a7ca-0af9fb49c71e@iki.fi |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 03/07/2023 20:54, Tomas Vondra wrote:
> Pushed, using the formula with two divisions (as in the original patch).
I ran into an issue with this, in the case of a small fillfactor and
wide tuple width:
On v16:
postgres=# create table t (data char(900)) with (fillfactor = 10,
autovacuum_enabled=off);
CREATE TABLE
postgres=# insert into t select g from generate_series(1, 1000) g;
INSERT 0 1000
postgres=# explain select count(*) from t;
QUERY PLAN
-------------------------------------------------------------
Aggregate (cost=1025.00..1025.01 rows=1 width=8)
-> Seq Scan on t (cost=0.00..1020.00 rows=2000 width=0)
(2 rows)
On v17:
QUERY PLAN
----------------------------------------------------------
Aggregate (cost=1000.00..1000.01 rows=1 width=8)
-> Seq Scan on t (cost=0.00..1000.00 rows=1 width=0)
(2 rows)
The new estimeate is 1 row, which is bad. Didn't change the plan in this
case, but I originally saw this in a test with more rows, and the
planner would not choose a parallel scan for the query because of that.
The calculation table_block_relation_estimate_size() in this case is:
tuple_width=3604
overhead_bytes_per_tuple=28
fillfactor=10
usable_bytes_per_page=8168
density = (usable_bytes_per_page * fillfactor / 100) / tuple_width
which gets rounded down to 0.
The straightforward fix is to clamp it to 1. The executor will always
place at least one tuple on a page, regardless of fillfactor.
--
Heikki Linnakangas
Neon (https://neon.tech)
From | Date | Subject | |
---|---|---|---|
Next Message | Melanie Plageman | 2025-01-29 19:12:52 | Re: Eagerly scan all-visible pages to amortize aggressive vacuum |
Previous Message | Ilia Evdokimov | 2025-01-29 18:52:21 | Re: Sample rate added to pg_stat_statements |