Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit29cf61a

Browse files
committed
Consider fillfactor when estimating relation size
When table_block_relation_estimate_size() estimated the number of tuplesin a relation without statistics (e.g. right after load), it did notconsider fillfactor when calculating density. With non-defaultfillfactor values, this may result in significant overestimate of thenumber of tuples - up to 10x with the minimum 10% fillfactor. This mayhave unexpected consequences, e.g. when creating hash indexes.This considers the current fillfactor value in the "no statistics" codepath. If the fillfactor changes after loading data into the table, theestimate may be off. But that seems much less likely than changing thefillfactor before the data load.Reviewed-by: Corey Huinker, Peter EisentrautDiscussion:https://postgr.es/m/cf154ef9-6bac-d268-b735-67a3443debba@enterprisedb.com
1 parent087a933 commit29cf61a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

‎src/backend/access/table/tableam.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,11 +737,19 @@ table_block_relation_estimate_size(Relation rel, int32 *attr_widths,
737737
* and (c) different table AMs might use different padding schemes.
738738
*/
739739
int32tuple_width;
740+
intfillfactor;
741+
742+
/*
743+
* Without reltuples/relpages, we also need to consider fillfactor.
744+
* The other branch considers it implicitly by calculating density
745+
* from actual relpages/reltuples statistics.
746+
*/
747+
fillfactor=RelationGetFillFactor(rel,HEAP_DEFAULT_FILLFACTOR);
740748

741749
tuple_width=get_rel_data_width(rel,attr_widths);
742750
tuple_width+=overhead_bytes_per_tuple;
743751
/* note: integer division is intentional here */
744-
density=usable_bytes_per_page /tuple_width;
752+
density=(usable_bytes_per_page*fillfactor /100) /tuple_width;
745753
}
746754
*tuples=rint(density* (double)curpages);
747755

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp