Re: Should heapam_estimate_rel_size consider fillfactor?

From: Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
To: 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: 2023-07-03 07:00:18
Message-ID: 10ed61c0-a078-9bdf-9ff4-dca92ffd5315@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 7/3/23 08:46, Peter Eisentraut wrote:
> On 14.06.23 20:41, Corey Huinker wrote:
>>     So maybe we should make table_block_relation_estimate_size smarter to
>>     also consider the fillfactor in the "no statistics" branch, per the
>>     attached patch.
>>
>>
>> I like this a lot. The reasoning is obvious, the fix is simple,it
>> doesn't upset any make-check-world tests, and in order to get a
>> performance regression we'd need a table whose fillfactor has been
>> changed after the data was loaded but before an analyze happens, and
>> that's a narrow enough case to accept.
>>
>> My only nitpick is to swap
>>
>>     (usable_bytes_per_page * fillfactor / 100) / tuple_width
>>
>> with
>>
>>     (usable_bytes_per_page * fillfactor) / (tuple_width * 100)
>>
>>
>> as this will eliminate the extra remainder truncation, and it also
>> gets the arguments "in order" algebraically.
>
> The fillfactor is in percent, so it makes sense to divide it by 100
> first before doing any further arithmetic with it.  I find your version
> of this to be more puzzling without any explanation.  You could do
> fillfactor/100.0 to avoid the integer division, but then, the comment
> above that says "integer division is intentional here", without any
> further explanation.  I think a bit more explanation of all the
> subtleties here would be good in any case.
>

Yeah, I guess the formula should be doing (fillfactor / 100.0).

The "integer division is intentional here" comment is unrelated to this
change, it refers to the division by "tuple_width" (and yeah, it'd be
nice to have it explain why it's intentional).

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-07-03 07:11:51 Re: Autogenerate some wait events code and documentation
Previous Message Michael Paquier 2023-07-03 06:57:42 Re: Autogenerate some wait events code and documentation