mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Standardize terminology for pg_statistic_ext entries.
Consistently refer to such an entry as a "statistics object", not just "statistics" or "extended statistics". Previously we had a mismash of terms, accompanied by utter confusion as to whether the term was singular or plural. That's not only grating (at least to the ear of a native English speaker) but could be outright misleading, eg in error messages that seemed to be referring to multiple objects where only one could be meant. This commit fixes the code and a lot of comments (though I may have missed a few). I also renamed two new SQL functions, pg_get_statisticsextdef -> pg_get_statisticsobjdef pg_statistic_ext_is_visible -> pg_statistics_obj_is_visible to conform better with this terminology. I have not touched the SGML docs other than fixing those function names; the docs certainly need work but it seems like a separable task. Discussion: https://postgr.es/m/22676.1494557205@sss.pgh.pa.us
This commit is contained in:
@@ -319,7 +319,7 @@ static char *pg_get_indexdef_worker(Oid indexrelid, int colno,
|
||||
const Oid *excludeOps,
|
||||
bool attrsOnly, bool showTblSpc,
|
||||
int prettyFlags, bool missing_ok);
|
||||
static char *pg_get_statisticsext_worker(Oid statextid, bool missing_ok);
|
||||
static char *pg_get_statisticsobj_worker(Oid statextid, bool missing_ok);
|
||||
static char *pg_get_partkeydef_worker(Oid relid, int prettyFlags,
|
||||
bool attrsOnly, bool missing_ok);
|
||||
static char *pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
|
||||
@@ -1425,16 +1425,16 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
|
||||
}
|
||||
|
||||
/*
|
||||
* pg_get_statisticsextdef
|
||||
* pg_get_statisticsobjdef
|
||||
* Get the definition of an extended statistics object
|
||||
*/
|
||||
Datum
|
||||
pg_get_statisticsextdef(PG_FUNCTION_ARGS)
|
||||
pg_get_statisticsobjdef(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid statextid = PG_GETARG_OID(0);
|
||||
char *res;
|
||||
|
||||
res = pg_get_statisticsext_worker(statextid, true);
|
||||
res = pg_get_statisticsobj_worker(statextid, true);
|
||||
|
||||
if (res == NULL)
|
||||
PG_RETURN_NULL();
|
||||
@@ -1446,7 +1446,7 @@ pg_get_statisticsextdef(PG_FUNCTION_ARGS)
|
||||
* Internal workhorse to decompile an extended statistics object.
|
||||
*/
|
||||
static char *
|
||||
pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
||||
pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
|
||||
{
|
||||
Form_pg_statistic_ext statextrec;
|
||||
HeapTuple statexttup;
|
||||
@@ -1467,7 +1467,7 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
||||
{
|
||||
if (missing_ok)
|
||||
return NULL;
|
||||
elog(ERROR, "cache lookup failed for extended statistics %u", statextid);
|
||||
elog(ERROR, "cache lookup failed for statistics object %u", statextid);
|
||||
}
|
||||
|
||||
statextrec = (Form_pg_statistic_ext) GETSTRUCT(statexttup);
|
||||
@@ -1480,8 +1480,7 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
||||
NameStr(statextrec->stxname)));
|
||||
|
||||
/*
|
||||
* Lookup the stxkind column so that we know how to handle the WITH
|
||||
* clause.
|
||||
* Decode the stxkind column so that we know which stats types to print.
|
||||
*/
|
||||
datum = SysCacheGetAttr(STATEXTOID, statexttup,
|
||||
Anum_pg_statistic_ext_stxkind, &isnull);
|
||||
@@ -1518,7 +1517,6 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
||||
appendStringInfoString(&buf, "ndistinct");
|
||||
else if (dependencies_enabled)
|
||||
appendStringInfoString(&buf, "dependencies");
|
||||
|
||||
appendStringInfoChar(&buf, ')');
|
||||
}
|
||||
|
||||
|
||||
@@ -3707,25 +3707,27 @@ estimate_multivariate_ndistinct(PlannerInfo *root, RelOptInfo *rel,
|
||||
{
|
||||
StatisticExtInfo *info = (StatisticExtInfo *) lfirst(lc);
|
||||
Bitmapset *shared;
|
||||
int nshared;
|
||||
|
||||
/* skip statistics of other kinds */
|
||||
if (info->kind != STATS_EXT_NDISTINCT)
|
||||
continue;
|
||||
|
||||
/* compute attnums shared by the vars and the statistic */
|
||||
/* compute attnums shared by the vars and the statistics object */
|
||||
shared = bms_intersect(info->keys, attnums);
|
||||
nshared = bms_num_members(shared);
|
||||
|
||||
/*
|
||||
* Does this statistics matches more columns than the currently
|
||||
* best statistic? If so, use this one instead.
|
||||
* Does this statistics object match more columns than the currently
|
||||
* best object? If so, use this one instead.
|
||||
*
|
||||
* XXX This should break ties using name of the statistic, or
|
||||
* something like that, to make the outcome stable.
|
||||
* XXX This should break ties using name of the object, or something
|
||||
* like that, to make the outcome stable.
|
||||
*/
|
||||
if (bms_num_members(shared) > nmatches)
|
||||
if (nshared > nmatches)
|
||||
{
|
||||
statOid = info->statOid;
|
||||
nmatches = bms_num_members(shared);
|
||||
nmatches = nshared;
|
||||
matched = shared;
|
||||
}
|
||||
}
|
||||
|
||||
4
src/backend/utils/cache/relcache.c
vendored
4
src/backend/utils/cache/relcache.c
vendored
@@ -4462,7 +4462,7 @@ RelationGetIndexList(Relation relation)
|
||||
|
||||
/*
|
||||
* RelationGetStatExtList
|
||||
* get a list of OIDs of extended statistics on this relation
|
||||
* get a list of OIDs of statistics objects on this relation
|
||||
*
|
||||
* The statistics list is created only if someone requests it, in a way
|
||||
* similar to RelationGetIndexList(). We scan pg_statistic_ext to find
|
||||
@@ -4470,7 +4470,7 @@ RelationGetIndexList(Relation relation)
|
||||
* won't have to compute it again. Note that shared cache inval of a
|
||||
* relcache entry will delete the old list and set rd_statvalid to 0,
|
||||
* so that we must recompute the statistics list on next request. This
|
||||
* handles creation or deletion of a statistic.
|
||||
* handles creation or deletion of a statistics object.
|
||||
*
|
||||
* The returned list is guaranteed to be sorted in order by OID, although
|
||||
* this is not currently needed.
|
||||
|
||||
Reference in New Issue
Block a user