From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | "Ryohei Takahashi (Fujitsu)" <r(dot)takahashi_2(at)fujitsu(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Can we use Statistics Import and Export feature to perforamance testing? |
Date: | 2025-04-12 12:31:34 |
Message-ID: | CAApHDvoKmg-otMDDWeGgHzsVF+TWc4-8+s9XxiXjMv6ZfvMFOA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, 12 Apr 2025 at 20:29, Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
>>
>> at the *actual size* of the relation and takes that into account when
>> scaling the statistics (see table_block_relation_estimate_size() in
>> tableam.c). If the table sizes don't match between the two servers
>> then there's no guarantees the planner will produce the same plan.
>
> Sorry that I didn't see this thread until now. I would like to note that table_block_relation_estimate_size() determines the actual size of the relation by asking pg_class, and the relevant values there are set by pg_restore_relation_stats().
Sorry, this isn't correct. I suspect you're probably misreading the
code. On a fleeting glance, you might have seen the "relpages =
(BlockNumber) rel->rd_rel->relpages;" line and come to this
conclusion. A more careful study will reveal the truth. Check for
"curpages = RelationGetNumberOfBlocks(rel);" and an unconditional
"*pages = curpages;".
You might be getting confused because the code does look at the
pg_class fields, but that's only to estimate the tuple density. When
pg_class has those estimates, they're used to calculate the estimated
density by doing reltuples / relpages, but that average rows per page
is then applied to the *actual* number of pages in the relation. This
method allows the stats to be scaled as the table grows and that take
effect without waiting for vacuum or analyze to update the pg_class
fields. The planner checks the current size of the table every time it
plans a query. That's very well understood and documented. See [1].
David
[1] https://www.postgresql.org/docs/current/row-estimation-examples.html#ROW-ESTIMATION-EXAMPLES
From | Date | Subject | |
---|---|---|---|
Next Message | Noah Misch | 2025-04-12 12:34:30 | Re: [18] Unintentional behavior change in commit e9931bfb75 |
Previous Message | Corey Huinker | 2025-04-12 09:03:48 | Re: someone else to do the list of acknowledgments |