Commit 2cf9cf5d authored by Michael Paquier's avatar Michael Paquier

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 a4d75c86.  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
parent 2a27dbae
...@@ -559,11 +559,11 @@ CreateStatistics(CreateStatsStmt *stmt) ...@@ -559,11 +559,11 @@ CreateStatistics(CreateStatsStmt *stmt)
} }
/* /*
* If there are no dependencies on a column, give the statistics an auto * If there are no dependencies on a column, give the statistics object an
* dependency on the whole table. In most cases, this will be redundant, * auto dependency on the whole table. In most cases, this will be
* but it might not be if the statistics expressions contain no Vars * redundant, but it might not be if the statistics expressions contain no
* (which might seem strange but possible). This is consistent with what * Vars (which might seem strange but possible). This is consistent with
* we do for indexes in index_create. * what we do for indexes in index_create.
* *
* XXX We intentionally don't consider the expressions before adding this * XXX We intentionally don't consider the expressions before adding this
* dependency, because recordDependencyOnSingleRelExpr may not create any * dependency, because recordDependencyOnSingleRelExpr may not create any
...@@ -648,9 +648,9 @@ AlterStatistics(AlterStatsStmt *stmt) ...@@ -648,9 +648,9 @@ AlterStatistics(AlterStatsStmt *stmt)
stxoid = get_statistics_object_oid(stmt->defnames, stmt->missing_ok); stxoid = get_statistics_object_oid(stmt->defnames, stmt->missing_ok);
/* /*
* If we got here and the OID is not valid, it means the statistics does * If we got here and the OID is not valid, it means the statistics object
* not exist, but the command specified IF EXISTS. So report this as a * does not exist, but the command specified IF EXISTS. So report this as
* simple NOTICE and we're done. * a simple NOTICE and we're done.
*/ */
if (!OidIsValid(stxoid)) if (!OidIsValid(stxoid))
{ {
...@@ -767,7 +767,7 @@ RemoveStatisticsById(Oid statsOid) ...@@ -767,7 +767,7 @@ RemoveStatisticsById(Oid statsOid)
} }
/* /*
* Select a nonconflicting name for a new statistics. * Select a nonconflicting name for a new statistics object.
* *
* name1, name2, and label are used the same way as for makeObjectName(), * name1, name2, and label are used the same way as for makeObjectName(),
* except that the label can't be NULL; digits will be appended to the label * except that the label can't be NULL; digits will be appended to the label
...@@ -814,9 +814,9 @@ ChooseExtendedStatisticName(const char *name1, const char *name2, ...@@ -814,9 +814,9 @@ ChooseExtendedStatisticName(const char *name1, const char *name2,
} }
/* /*
* Generate "name2" for a new statistics given the list of column names for it * Generate "name2" for a new statistics object given the list of column
* This will be passed to ChooseExtendedStatisticName along with the parent * names for it. This will be passed to ChooseExtendedStatisticName along
* table name and a suitable label. * with the parent table name and a suitable label.
* *
* We know that less than NAMEDATALEN characters will actually be used, * We know that less than NAMEDATALEN characters will actually be used,
* so we can truncate the result once we've generated that many. * so we can truncate the result once we've generated that many.
...@@ -868,8 +868,8 @@ ChooseExtendedStatisticNameAddition(List *exprs) ...@@ -868,8 +868,8 @@ ChooseExtendedStatisticNameAddition(List *exprs)
} }
/* /*
* StatisticsGetRelation: given a statistics's relation OID, get the OID of * StatisticsGetRelation: given a statistics object's OID, get the OID of
* the relation it is an statistics on. Uses the system cache. * the relation it is defined on. Uses the system cache.
*/ */
Oid Oid
StatisticsGetRelation(Oid statId, bool missing_ok) StatisticsGetRelation(Oid statId, bool missing_ok)
......
...@@ -12465,13 +12465,13 @@ RememberStatisticsForRebuilding(Oid stxoid, AlteredTableInfo *tab) ...@@ -12465,13 +12465,13 @@ RememberStatisticsForRebuilding(Oid stxoid, AlteredTableInfo *tab)
/* /*
* This de-duplication check is critical for two independent reasons: we * This de-duplication check is critical for two independent reasons: we
* mustn't try to recreate the same statistics object twice, and if the * mustn't try to recreate the same statistics object twice, and if the
* statistics depends on more than one column whose type is to be altered, * statistics object depends on more than one column whose type is to be
* we must capture its definition string before applying any of the type * altered, we must capture its definition string before applying any of
* changes. ruleutils.c will get confused if we ask again later. * the type changes. ruleutils.c will get confused if we ask again later.
*/ */
if (!list_member_oid(tab->changedStatisticsOids, stxoid)) if (!list_member_oid(tab->changedStatisticsOids, stxoid))
{ {
/* OK, capture the index's existing definition string */ /* OK, capture the statistics object's existing definition string */
char *defstring = pg_get_statisticsobjdef_string(stxoid); char *defstring = pg_get_statisticsobjdef_string(stxoid);
tab->changedStatisticsOids = lappend_oid(tab->changedStatisticsOids, tab->changedStatisticsOids = lappend_oid(tab->changedStatisticsOids,
......
...@@ -2893,7 +2893,7 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString) ...@@ -2893,7 +2893,7 @@ transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
/* /*
* transformStatsStmt - parse analysis for CREATE STATISTICS * transformStatsStmt - parse analysis for CREATE STATISTICS
* *
* To avoid race conditions, it's important that this function rely only on * To avoid race conditions, it's important that this function relies only on
* the passed-in relid (and not on stmt->relation) to determine the target * the passed-in relid (and not on stmt->relation) to determine the target
* relation. * relation.
*/ */
...@@ -2949,7 +2949,7 @@ transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString) ...@@ -2949,7 +2949,7 @@ transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
if (list_length(pstate->p_rtable) != 1) if (list_length(pstate->p_rtable) != 1)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE), (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("statistics expressions can refer only to the table being indexed"))); errmsg("statistics expressions can refer only to the table being referenced")));
free_parsestate(pstate); free_parsestate(pstate);
...@@ -3616,7 +3616,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, ...@@ -3616,7 +3616,7 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
newcmds = lappend(newcmds, newcmd); newcmds = lappend(newcmds, newcmd);
} }
/* Append extended statistic objects */ /* Append extended statistics objects */
transformExtendedStatistics(&cxt); transformExtendedStatistics(&cxt);
/* Close rel */ /* Close rel */
......
...@@ -182,7 +182,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows, ...@@ -182,7 +182,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
continue; continue;
} }
/* compute statistics target for this statistics */ /* compute statistics target for this statistics object */
stattarget = statext_compute_stattarget(stat->stattarget, stattarget = statext_compute_stattarget(stat->stattarget,
bms_num_members(stat->columns), bms_num_members(stat->columns),
stats); stats);
...@@ -195,7 +195,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows, ...@@ -195,7 +195,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
if (stattarget == 0) if (stattarget == 0)
continue; continue;
/* evaluate expressions (if the statistics has any) */ /* evaluate expressions (if the statistics object has any) */
data = make_build_data(onerel, stat, numrows, rows, stats, stattarget); data = make_build_data(onerel, stat, numrows, rows, stats, stattarget);
/* compute statistic of each requested type */ /* compute statistic of each requested type */
...@@ -257,9 +257,9 @@ BuildRelationExtStatistics(Relation onerel, double totalrows, ...@@ -257,9 +257,9 @@ BuildRelationExtStatistics(Relation onerel, double totalrows,
* when analyzing only some of the columns, this will skip statistics objects * when analyzing only some of the columns, this will skip statistics objects
* that would require additional columns. * that would require additional columns.
* *
* See statext_compute_stattarget for details about how we compute statistics * See statext_compute_stattarget for details about how we compute the
* target for a statistics object (from the object target, attribute targets * statistics target for a statistics object (from the object target,
* and default statistics target). * attribute targets and default statistics target).
*/ */
int int
ComputeExtStatisticsRows(Relation onerel, ComputeExtStatisticsRows(Relation onerel,
...@@ -329,8 +329,8 @@ ComputeExtStatisticsRows(Relation onerel, ...@@ -329,8 +329,8 @@ ComputeExtStatisticsRows(Relation onerel,
* *
* When computing target for extended statistics objects, we consider three * When computing target for extended statistics objects, we consider three
* places where the target may be set - the statistics object itself, * places where the target may be set - the statistics object itself,
* attributes the statistics is defined on, and then the default statistics * attributes the statistics object is defined on, and then the default
* target. * statistics target.
* *
* First we look at what's set for the statistics object itself, using the * First we look at what's set for the statistics object itself, using the
* ALTER STATISTICS ... SET STATISTICS command. If we find a valid value * 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 ...@@ -1789,8 +1789,8 @@ statext_mcv_clauselist_selectivity(PlannerInfo *root, List *clauses, int varReli
/* /*
* The clause was not estimated yet, and we've extracted either * The clause was not estimated yet, and we've extracted either
* attnums of expressions from it. Ignore it if it's not fully * attnums or expressions from it. Ignore it if it's not fully
* covered by the chosen statistics. * covered by the chosen statistics object.
* *
* We need to check both attributes and expressions, and reject if * We need to check both attributes and expressions, and reject if
* either is not covered. * either is not covered.
......
...@@ -3443,13 +3443,13 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, ...@@ -3443,13 +3443,13 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows,
* expression, treat it as a single variable even if it's really more * expression, treat it as a single variable even if it's really more
* complicated. * complicated.
* *
* XXX This has the consequence that if there's a statistics on the * XXX This has the consequence that if there's a statistics object on
* expression, we don't split it into individual Vars. This affects * the expression, we don't split it into individual Vars. This
* our selection of statistics in estimate_multivariate_ndistinct, * affects our selection of statistics in
* because it's probably better to use more accurate estimate for each * estimate_multivariate_ndistinct, because it's probably better to
* expression and treat them as independent, than to combine estimates * use more accurate estimate for each expression and treat them as
* for the extracted variables when we don't know how that relates to * independent, than to combine estimates for the extracted variables
* the expressions. * when we don't know how that relates to the expressions.
*/ */
examine_variable(root, groupexpr, 0, &vardata); examine_variable(root, groupexpr, 0, &vardata);
if (HeapTupleIsValid(vardata.statsTuple) || vardata.isunique) if (HeapTupleIsValid(vardata.statsTuple) || vardata.isunique)
...@@ -3918,7 +3918,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, ...@@ -3918,7 +3918,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
if (!rel->statlist) if (!rel->statlist)
return false; return false;
/* look for the ndistinct statistics matching the most vars */ /* look for the ndistinct statistics object matching the most vars */
nmatches_vars = 0; /* we require at least two matches */ nmatches_vars = 0; /* we require at least two matches */
nmatches_exprs = 0; nmatches_exprs = 0;
foreach(lc, rel->statlist) foreach(lc, rel->statlist)
...@@ -3964,7 +3964,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, ...@@ -3964,7 +3964,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
continue; continue;
} }
/* expression - see if it's in the statistics */ /* expression - see if it's in the statistics object */
foreach(lc3, info->exprs) foreach(lc3, info->exprs)
{ {
Node *expr = (Node *) lfirst(lc3); Node *expr = (Node *) lfirst(lc3);
...@@ -4053,7 +4053,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, ...@@ -4053,7 +4053,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
if (!AttrNumberIsForUserDefinedAttr(attnum)) if (!AttrNumberIsForUserDefinedAttr(attnum))
continue; continue;
/* Is the variable covered by the statistics? */ /* Is the variable covered by the statistics object? */
if (!bms_is_member(attnum, matched_info->keys)) if (!bms_is_member(attnum, matched_info->keys))
continue; continue;
...@@ -4075,7 +4075,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel, ...@@ -4075,7 +4075,7 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
if (found) if (found)
continue; continue;
/* expression - see if it's in the statistics */ /* expression - see if it's in the statistics object */
idx = 0; idx = 0;
foreach(lc3, matched_info->exprs) foreach(lc3, matched_info->exprs)
{ {
...@@ -5252,7 +5252,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, ...@@ -5252,7 +5252,7 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
{ {
HeapTuple t = statext_expressions_load(info->statOid, pos); HeapTuple t = statext_expressions_load(info->statOid, pos);
/* Get index's table for permission check */ /* Get statistics object's table for permission check */
RangeTblEntry *rte; RangeTblEntry *rte;
Oid userid; Oid userid;
...@@ -5276,8 +5276,8 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid, ...@@ -5276,8 +5276,8 @@ examine_variable(PlannerInfo *root, Node *node, int varRelid,
/* /*
* For simplicity, we insist on the whole table being * For simplicity, we insist on the whole table being
* selectable, rather than trying to identify which * selectable, rather than trying to identify which
* column(s) the statistics depends on. Also require all * column(s) the statistics object depends on. Also
* rows to be selectable --- there must be no * require all rows to be selectable --- there must be no
* securityQuals from security barrier views or RLS * securityQuals from security barrier views or RLS
* policies. * policies.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment