diff options
Diffstat (limited to 'src/backend/statistics/extended_stats.c')
| -rw-r--r-- | src/backend/statistics/extended_stats.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index b334140c48..3f74cee05f 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -3,7 +3,7 @@ * extended_stats.c * POSTGRES extended statistics * - * Generic code supporting statistic objects created via CREATE STATISTICS. + * Generic code supporting statistics objects created via CREATE STATISTICS. * * * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group @@ -35,14 +35,15 @@ /* - * Used internally to refer to an individual pg_statistic_ext entry. + * Used internally to refer to an individual statistics object, i.e., + * a pg_statistic_ext entry. */ typedef struct StatExtEntry { Oid statOid; /* OID of pg_statistic_ext entry */ - char *schema; /* statistics schema */ - char *name; /* statistics name */ - Bitmapset *columns; /* attribute numbers covered by the statistics */ + char *schema; /* statistics object's schema */ + char *name; /* statistics object's name */ + Bitmapset *columns; /* attribute numbers covered by the object */ List *types; /* 'char' list of enabled statistic kinds */ } StatExtEntry; @@ -59,8 +60,8 @@ static void statext_store(Relation pg_stext, Oid relid, * Compute requested extended stats, using the rows sampled for the plain * (single-column) stats. * - * This fetches a list of stats from pg_statistic_ext, computes the stats - * and serializes them back into the catalog (as bytea values). + * This fetches a list of stats types from pg_statistic_ext, computes the + * requested stats, and serializes them back into the catalog. */ void BuildRelationExtStatistics(Relation onerel, double totalrows, @@ -98,7 +99,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows, { ereport(WARNING, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("extended statistics \"%s.%s\" could not be collected for relation %s.%s", + errmsg("statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"", stat->schema, stat->name, get_namespace_name(onerel->rd_rel->relnamespace), RelationGetRelationName(onerel)), @@ -110,7 +111,7 @@ BuildRelationExtStatistics(Relation onerel, double totalrows, Assert(bms_num_members(stat->columns) >= 2 && bms_num_members(stat->columns) <= STATS_MAX_DIMENSIONS); - /* compute statistic of each type */ + /* compute statistic of each requested type */ foreach(lc2, stat->types) { char t = (char) lfirst_int(lc2); @@ -160,7 +161,7 @@ statext_is_kind_built(HeapTuple htup, char type) } /* - * Return a list (of StatExtEntry) of statistics for the given relation. + * Return a list (of StatExtEntry) of statistics objects for the given relation. */ static List * fetch_statentries_for_relation(Relation pg_statext, Oid relid) @@ -171,7 +172,7 @@ fetch_statentries_for_relation(Relation pg_statext, Oid relid) List *result = NIL; /* - * Prepare to scan pg_statistic_ext for entries having indrelid = this + * Prepare to scan pg_statistic_ext for entries having stxrelid = this * rel. */ ScanKeyInit(&skey, @@ -329,7 +330,7 @@ statext_store(Relation pg_stext, Oid statOid, /* there should already be a pg_statistic_ext tuple */ oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid)); if (!HeapTupleIsValid(oldtup)) - elog(ERROR, "cache lookup failed for extended statistics %u", statOid); + elog(ERROR, "cache lookup failed for statistics object %u", statOid); /* replace it */ stup = heap_modify_tuple(oldtup, @@ -433,7 +434,7 @@ multi_sort_compare_dims(int start, int end, /* * has_stats_of_kind - * Check that the list contains statistic of a given kind + * Check whether the list contains statistic of a given kind */ bool has_stats_of_kind(List *stats, char requiredkind) @@ -458,11 +459,12 @@ has_stats_of_kind(List *stats, char requiredkind) * there's no match. * * The current selection criteria is very simple - we choose the statistics - * referencing the most attributes with the least keys. + * object referencing the most of the requested attributes, breaking ties + * in favor of objects with fewer keys overall. * - * XXX if multiple statistics exists of the same size matching the same number - * of keys, then the statistics which are chosen depend on the order that they - * appear in the stats list. Perhaps this needs to be more definitive. + * XXX if multiple statistics objects tie on both criteria, then which object + * is chosen depends on the order that they appear in the stats list. Perhaps + * further tiebreakers are needed. */ StatisticExtInfo * choose_best_statistics(List *stats, Bitmapset *attnums, char requiredkind) @@ -479,7 +481,7 @@ choose_best_statistics(List *stats, Bitmapset *attnums, char requiredkind) int numkeys; Bitmapset *matched; - /* skip statistics that are not the correct type */ + /* skip statistics that are not of the correct type */ if (info->kind != requiredkind) continue; @@ -495,9 +497,9 @@ choose_best_statistics(List *stats, Bitmapset *attnums, char requiredkind) numkeys = bms_num_members(info->keys); /* - * Use these statistics when it increases the number of matched - * clauses or when it matches the same number of attributes but these - * stats have fewer keys than any previous match. + * Use this object when it increases the number of matched clauses or + * when it matches the same number of attributes but these stats have + * fewer keys than any previous match. */ if (num_matched > best_num_matched || (num_matched == best_num_matched && numkeys < best_match_keys)) |
