Skip to content

Commit 070d2e1

Browse files
committed
Clarify use of "statistics objects" in the code
The code inconsistently used "statistic object" or "statistics" where the correct term, as discussed, is actually "statistics object". This improves the state of the code to be more consistent. While on it, fix an incorrect error message introduced in a4d75c8. This error should never happen, as the code states, but it would be misleading. Author: Justin Pryzby Reviewed-by: Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/20210924215827.GS831@telsasoft.com Backpatch-through: 14
1 parent 0b947c3 commit 070d2e1

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

src/backend/commands/statscmds.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -560,11 +560,11 @@ CreateStatistics(CreateStatsStmt *stmt)
560560
}
561561

562562
/*
563-
* If there are no dependencies on a column, give the statistics an auto
564-
* dependency on the whole table. In most cases, this will be redundant,
565-
* but it might not be if the statistics expressions contain no Vars
566-
* (which might seem strange but possible). This is consistent with what
567-
* we do for indexes in index_create.
563+
* If there are no dependencies on a column, give the statistics object an
564+
* auto dependency on the whole table. In most cases, this will be
565+
* redundant, but it might not be if the statistics expressions contain no
566+
* Vars (which might seem strange but possible). This is consistent with
567+
* what we do for indexes in index_create.
568568
*
569569
* XXX We intentionally don't consider the expressions before adding this
570570
* dependency, because recordDependencyOnSingleRelExpr may not create any
@@ -649,9 +649,9 @@ AlterStatistics(AlterStatsStmt *stmt)
649649
stxoid = get_statistics_object_oid(stmt->defnames, stmt->missing_ok);
650650

651651
/*
652-
* If we got here and the OID is not valid, it means the statistics does
653-
* not exist, but the command specified IF EXISTS. So report this as a
654-
* simple NOTICE and we're done.
652+
* If we got here and the OID is not valid, it means the statistics object
653+
* does not exist, but the command specified IF EXISTS. So report this as
654+
* a simple NOTICE and we're done.
655655
*/
656656
if (!OidIsValid(stxoid))
657657
{
@@ -768,7 +768,7 @@ RemoveStatisticsById(Oid statsOid)
768768
}
769769

770770
/*
771-
* Select a nonconflicting name for a new statistics.
771+
* Select a nonconflicting name for a new statistics object.
772772
*
773773
* name1, name2, and label are used the same way as for makeObjectName(),
774774
* except that the label can't be NULL; digits will be appended to the label
@@ -815,9 +815,9 @@ ChooseExtendedStatisticName(const char *name1, const char *name2,
815815
}
816816

817817
/*
818-
* Generate "name2" for a new statistics given the list of column names for it
819-
* This will be passed to ChooseExtendedStatisticName along with the parent
820-
* table name and a suitable label.
818+
* Generate "name2" for a new statistics object given the list of column
819+
* names for it. This will be passed to ChooseExtendedStatisticName along
820+
* with the parent table name and a suitable label.
821821
*
822822
* We know that less than NAMEDATALEN characters will actually be used,
823823
* so we can truncate the result once we've generated that many.
@@ -869,8 +869,8 @@ ChooseExtendedStatisticNameAddition(List *exprs)
869869
}
870870

871871
/*
872-
* StatisticsGetRelation: given a statistics's relation OID, get the OID of
873-
* the relation it is an statistics on. Uses the system cache.
872+
* StatisticsGetRelation: given a statistics object's OID, get the OID of
873+
* the relation it is defined on. Uses the system cache.
874874
*/
875875
Oid
876876
StatisticsGetRelation(Oid statId, bool missing_ok)

src/backend/commands/tablecmds.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -12585,13 +12585,13 @@ RememberStatisticsForRebuilding(Oid stxoid, AlteredTableInfo *tab)
1258512585
/*
1258612586
* This de-duplication check is critical for two independent reasons: we
1258712587
* mustn't try to recreate the same statistics object twice, and if the
12588-
* statistics depends on more than one column whose type is to be altered,
12589-
* we must capture its definition string before applying any of the type
12590-
* changes. ruleutils.c will get confused if we ask again later.
12588+
* statistics object depends on more than one column whose type is to be
12589+
* altered, we must capture its definition string before applying any of
12590+
* the type changes. ruleutils.c will get confused if we ask again later.
1259112591
*/
1259212592
if (!list_member_oid(tab->changedStatisticsOids, stxoid))
1259312593
{
12594-
/* OK, capture the index's existing definition string */
12594+
/* OK, capture the statistics object's existing definition string */
1259512595
char *defstring = pg_get_statisticsobjdef_string(stxoid);
1259612596

1259712597
tab->changedStatisticsOids = lappend_oid(tab->changedStatisticsOids,

src/backend/parser/parse_utilcmd.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
28922892
/*
28932893
* transformStatsStmt - parse analysis for CREATE STATISTICS
28942894
*
2895-
* To avoid race conditions, it's important that this function rely only on
2895+
* To avoid race conditions, it's important that this function relies only on
28962896
* the passed-in relid (and not on stmt->relation) to determine the target
28972897
* relation.
28982898
*/
@@ -2948,7 +2948,7 @@ transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
29482948
if (list_length(pstate->p_rtable) != 1)
29492949
ereport(ERROR,
29502950
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2951-
errmsg("statistics expressions can refer only to the table being indexed")));
2951+
errmsg("statistics expressions can refer only to the table being referenced")));
29522952

29532953
free_parsestate(pstate);
29542954

@@ -3615,7 +3615,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
36153615
newcmds = lappend(newcmds, newcmd);
36163616
}
36173617

3618-
/* Append extended statistic objects */
3618+
/* Append extended statistics objects */
36193619
transformExtendedStatistics(&cxt);
36203620

36213621
/* Close rel */

src/backend/statistics/extended_stats.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
182182
continue;
183183
}
184184

185-
/* compute statistics target for this statistics */
185+
/* compute statistics target for this statistics object */
186186
stattarget = statext_compute_stattarget(stat->stattarget,
187187
bms_num_members(stat->columns),
188188
stats);
@@ -195,7 +195,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
195195
if (stattarget == 0)
196196
continue;
197197

198-
/* evaluate expressions (if the statistics has any) */
198+
/* evaluate expressions (if the statistics object has any) */
199199
data = make_build_data(onerel, stat, numrows, rows, stats, stattarget);
200200

201201
/* compute statistic of each requested type */
@@ -257,9 +257,9 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
257257
* when analyzing only some of the columns, this will skip statistics objects
258258
* that would require additional columns.
259259
*
260-
* See statext_compute_stattarget for details about how we compute statistics
261-
* target for a statistics object (from the object target, attribute targets
262-
* and default statistics target).
260+
* See statext_compute_stattarget for details about how we compute the
261+
* statistics target for a statistics object (from the object target,
262+
* attribute targets and default statistics target).
263263
*/
264264
int
265265
ComputeExtStatisticsRows(Relation onerel,
@@ -329,8 +329,8 @@ ComputeExtStatisticsRows(Relation onerel,
329329
*
330330
* When computing target for extended statistics objects, we consider three
331331
* places where the target may be set - the statistics object itself,
332-
* attributes the statistics is defined on, and then the default statistics
333-
* target.
332+
* attributes the statistics object is defined on, and then the default
333+
* statistics target.
334334
*
335335
* First we look at what's set for the statistics object itself, using the
336336
* ALTER STATISTICS ... SET STATISTICS command. If we find a valid value
@@ -1789,8 +1789,8 @@ statext_mcv_clauselist_selectivity(PlannerInfo *root, List *clauses, int varReli
17891789

17901790
/*
17911791
* The clause was not estimated yet, and we've extracted either
1792-
* attnums of expressions from it. Ignore it if it's not fully
1793-
* covered by the chosen statistics.
1792+
* attnums or expressions from it. Ignore it if it's not fully
1793+
* covered by the chosen statistics object.
17941794
*
17951795
* We need to check both attributes and expressions, and reject if
17961796
* either is not covered.

src/backend/utils/adt/selfuncs.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -3443,13 +3443,13 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows,
34433443
* expression, treat it as a single variable even if it's really more
34443444
* complicated.
34453445
*
3446-
* XXX This has the consequence that if there's a statistics on the
3447-
* expression, we don't split it into individual Vars. This affects
3448-
* our selection of statistics in estimate_multivariate_ndistinct,
3449-
* because it's probably better to use more accurate estimate for each
3450-
* expression and treat them as independent, than to combine estimates
3451-
* for the extracted variables when we don't know how that relates to
3452-
* the expressions.
3446+
* XXX This has the consequence that if there's a statistics object on
3447+
* the expression, we don't split it into individual Vars. This
3448+
* affects our selection of statistics in
3449+
* estimate_multivariate_ndistinct, because it's probably better to
3450+
* use more accurate estimate for each expression and treat them as
3451+
* independent, than to combine estimates for the extracted variables
3452+
* when we don't know how that relates to the expressions.
34533453
*/
34543454
examine_variable(root, groupexpr, 0, &vardata);
34553455
if (HeapTupleIsValid(vardata.statsTuple) || vardata.isunique)
@@ -3918,7 +3918,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
39183918
if (!rel->statlist)
39193919
return false;
39203920

3921-
/* look for the ndistinct statistics matching the most vars */
3921+
/* look for the ndistinct statistics object matching the most vars */
39223922
nmatches_vars = 0; /* we require at least two matches */
39233923
nmatches_exprs = 0;
39243924
foreach(lc, rel->statlist)
@@ -3964,7 +3964,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
39643964
continue;
39653965
}
39663966

3967-
/* expression - see if it's in the statistics */
3967+
/* expression - see if it's in the statistics object */
39683968
foreach(lc3, info->exprs)
39693969
{
39703970
Node *expr = (Node *) lfirst(lc3);
@@ -4053,7 +4053,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
40534053
if (!AttrNumberIsForUserDefinedAttr(attnum))
40544054
continue;
40554055

4056-
/* Is the variable covered by the statistics? */
4056+
/* Is the variable covered by the statistics object? */
40574057
if (!bms_is_member(attnum, matched_info->keys))
40584058
continue;
40594059

@@ -4075,7 +4075,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
40754075
if (found)
40764076
continue;
40774077

4078-
/* expression - see if it's in the statistics */
4078+
/* expression - see if it's in the statistics object */
40794079
idx = 0;
40804080
foreach(lc3, matched_info->exprs)
40814081
{
@@ -5252,7 +5252,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
52525252
{
52535253
HeapTuple t = statext_expressions_load(info->statOid, pos);
52545254

5255-
/* Get index's table for permission check */
5255+
/* Get statistics object's table for permission check */
52565256
RangeTblEntry *rte;
52575257
Oid userid;
52585258

@@ -5276,8 +5276,8 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
52765276
/*
52775277
* For simplicity, we insist on the whole table being
52785278
* selectable, rather than trying to identify which
5279-
* column(s) the statistics depends on. Also require all
5280-
* rows to be selectable --- there must be no
5279+
* column(s) the statistics object depends on. Also
5280+
* require all rows to be selectable --- there must be no
52815281
* securityQuals from security barrier views or RLS
52825282
* policies.
52835283
*/

0 commit comments

Comments
 (0)