summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/plancat.c
diff options
context:
space:
mode:
authorTom Lane2022-05-12 19:17:30 +0000
committerTom Lane2022-05-12 19:17:30 +0000
commit23e7b38bfe396f919fdb66057174d29e17086418 (patch)
tree335c3962ef8afe0f6193d0413dbc51642276b147 /src/backend/optimizer/util/plancat.c
parent93909599cdba64c8759d646983c0a4ef93de1e50 (diff)
Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files. I manually fixed a couple of comments that pgindent uglified.
Diffstat (limited to 'src/backend/optimizer/util/plancat.c')
-rw-r--r--src/backend/optimizer/util/plancat.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index df97b799174..5012bfe1425 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -968,102 +968,102 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
if (RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind))
{
- table_relation_estimate_size(rel, attr_widths, pages, tuples,
- allvisfrac);
+ table_relation_estimate_size(rel, attr_widths, pages, tuples,
+ allvisfrac);
}
else if (rel->rd_rel->relkind == RELKIND_INDEX)
{
- /*
- * XXX: It'd probably be good to move this into a callback,
- * individual index types e.g. know if they have a metapage.
- */
+ /*
+ * XXX: It'd probably be good to move this into a callback, individual
+ * index types e.g. know if they have a metapage.
+ */
- /* it has storage, ok to call the smgr */
- curpages = RelationGetNumberOfBlocks(rel);
+ /* it has storage, ok to call the smgr */
+ curpages = RelationGetNumberOfBlocks(rel);
- /* report estimated # pages */
- *pages = curpages;
- /* quick exit if rel is clearly empty */
- if (curpages == 0)
- {
- *tuples = 0;
- *allvisfrac = 0;
- return;
- }
+ /* report estimated # pages */
+ *pages = curpages;
+ /* quick exit if rel is clearly empty */
+ if (curpages == 0)
+ {
+ *tuples = 0;
+ *allvisfrac = 0;
+ return;
+ }
- /* coerce values in pg_class to more desirable types */
- relpages = (BlockNumber) rel->rd_rel->relpages;
- reltuples = (double) rel->rd_rel->reltuples;
- relallvisible = (BlockNumber) rel->rd_rel->relallvisible;
+ /* coerce values in pg_class to more desirable types */
+ relpages = (BlockNumber) rel->rd_rel->relpages;
+ reltuples = (double) rel->rd_rel->reltuples;
+ relallvisible = (BlockNumber) rel->rd_rel->relallvisible;
+ /*
+ * Discount the metapage while estimating the number of tuples. This
+ * is a kluge because it assumes more than it ought to about index
+ * structure. Currently it's OK for btree, hash, and GIN indexes but
+ * suspect for GiST indexes.
+ */
+ if (relpages > 0)
+ {
+ curpages--;
+ relpages--;
+ }
+
+ /* estimate number of tuples from previous tuple density */
+ if (reltuples >= 0 && relpages > 0)
+ density = reltuples / (double) relpages;
+ else
+ {
/*
- * Discount the metapage while estimating the number of tuples.
- * This is a kluge because it assumes more than it ought to about
- * index structure. Currently it's OK for btree, hash, and GIN
- * indexes but suspect for GiST indexes.
+ * If we have no data because the relation was never vacuumed,
+ * estimate tuple width from attribute datatypes. We assume here
+ * that the pages are completely full, which is OK for tables
+ * (since they've presumably not been VACUUMed yet) but is
+ * probably an overestimate for indexes. Fortunately
+ * get_relation_info() can clamp the overestimate to the parent
+ * table's size.
+ *
+ * Note: this code intentionally disregards alignment
+ * considerations, because (a) that would be gilding the lily
+ * considering how crude the estimate is, and (b) it creates
+ * platform dependencies in the default plans which are kind of a
+ * headache for regression testing.
+ *
+ * XXX: Should this logic be more index specific?
*/
- if (relpages > 0)
- {
- curpages--;
- relpages--;
- }
-
- /* estimate number of tuples from previous tuple density */
- if (reltuples >= 0 && relpages > 0)
- density = reltuples / (double) relpages;
- else
- {
- /*
- * If we have no data because the relation was never vacuumed,
- * estimate tuple width from attribute datatypes. We assume
- * here that the pages are completely full, which is OK for
- * tables (since they've presumably not been VACUUMed yet) but
- * is probably an overestimate for indexes. Fortunately
- * get_relation_info() can clamp the overestimate to the
- * parent table's size.
- *
- * Note: this code intentionally disregards alignment
- * considerations, because (a) that would be gilding the lily
- * considering how crude the estimate is, and (b) it creates
- * platform dependencies in the default plans which are kind
- * of a headache for regression testing.
- *
- * XXX: Should this logic be more index specific?
- */
- int32 tuple_width;
+ int32 tuple_width;
- tuple_width = get_rel_data_width(rel, attr_widths);
- tuple_width += MAXALIGN(SizeofHeapTupleHeader);
- tuple_width += sizeof(ItemIdData);
- /* note: integer division is intentional here */
- density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width;
- }
- *tuples = rint(density * (double) curpages);
+ tuple_width = get_rel_data_width(rel, attr_widths);
+ tuple_width += MAXALIGN(SizeofHeapTupleHeader);
+ tuple_width += sizeof(ItemIdData);
+ /* note: integer division is intentional here */
+ density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width;
+ }
+ *tuples = rint(density * (double) curpages);
- /*
- * We use relallvisible as-is, rather than scaling it up like we
- * do for the pages and tuples counts, on the theory that any
- * pages added since the last VACUUM are most likely not marked
- * all-visible. But costsize.c wants it converted to a fraction.
- */
- if (relallvisible == 0 || curpages <= 0)
- *allvisfrac = 0;
- else if ((double) relallvisible >= curpages)
- *allvisfrac = 1;
- else
- *allvisfrac = (double) relallvisible / curpages;
+ /*
+ * We use relallvisible as-is, rather than scaling it up like we do
+ * for the pages and tuples counts, on the theory that any pages added
+ * since the last VACUUM are most likely not marked all-visible. But
+ * costsize.c wants it converted to a fraction.
+ */
+ if (relallvisible == 0 || curpages <= 0)
+ *allvisfrac = 0;
+ else if ((double) relallvisible >= curpages)
+ *allvisfrac = 1;
+ else
+ *allvisfrac = (double) relallvisible / curpages;
}
else
{
- /*
- * Just use whatever's in pg_class. This covers foreign tables,
- * sequences, and also relkinds without storage (shouldn't get
- * here?); see initializations in AddNewRelationTuple(). Note
- * that FDW must cope if reltuples is -1!
- */
- *pages = rel->rd_rel->relpages;
- *tuples = rel->rd_rel->reltuples;
- *allvisfrac = 0;
+ /*
+ * Just use whatever's in pg_class. This covers foreign tables,
+ * sequences, and also relkinds without storage (shouldn't get here?);
+ * see initializations in AddNewRelationTuple(). Note that FDW must
+ * cope if reltuples is -1!
+ */
+ *pages = rel->rd_rel->relpages;
+ *tuples = rel->rd_rel->reltuples;
+ *allvisfrac = 0;
}
}