mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Rename columns in new pg_statistic_ext catalog
The new catalog reused a column prefix "sta" from pg_statistic, but this is undesirable, so change the catalog to use prefix "stx" instead. Also, rename the column that lists enabled statistic kinds as "stxkind" rather than "enabled". Discussion: https://postgr.es/m/CAKJS1f_2t5jhSN7huYRFH3w3rrHfG2QU7hiUHsu-Vdjd1rYT3w@mail.gmail.com
This commit is contained in:
@ -4291,21 +4291,21 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>starelid</structfield></entry>
|
<entry><structfield>stxrelid</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
|
||||||
<entry>The table that the described columns belongs to</entry>
|
<entry>The table that the described columns belongs to</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>staname</structfield></entry>
|
<entry><structfield>stxname</structfield></entry>
|
||||||
<entry><type>name</type></entry>
|
<entry><type>name</type></entry>
|
||||||
<entry></entry>
|
<entry></entry>
|
||||||
<entry>Name of the statistic.</entry>
|
<entry>Name of the statistic.</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>stanamespace</structfield></entry>
|
<entry><structfield>stxnamespace</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.oid</literal></entry>
|
||||||
<entry>
|
<entry>
|
||||||
@ -4314,24 +4314,26 @@
|
|||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>staowner</structfield></entry>
|
<entry><structfield>stxowner</structfield></entry>
|
||||||
<entry><type>oid</type></entry>
|
<entry><type>oid</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-authid"><structname>pg_authid</structname></link>.oid</literal></entry>
|
<entry><literal><link linkend="catalog-pg-authid"><structname>pg_authid</structname></link>.oid</literal></entry>
|
||||||
<entry>Owner of the statistic</entry>
|
<entry>Owner of the statistic</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>staenabled</structfield></entry>
|
<entry><structfield>stxkind</structfield></entry>
|
||||||
<entry><type>char[]</type></entry>
|
<entry><type>char[]</type></entry>
|
||||||
<entry></entry>
|
<entry></entry>
|
||||||
<entry>
|
<entry>
|
||||||
An array with the modes of the enabled statistic types, encoded as
|
An array with the modes of the enabled statistic types. Valid values
|
||||||
<literal>d</literal> for ndistinct coefficients.
|
are:
|
||||||
|
<literal>d</literal> for ndistinct coefficients,
|
||||||
|
<literal>f</literal> for functional dependencies.
|
||||||
</entry>
|
</entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>stakeys</structfield></entry>
|
<entry><structfield>stxkeys</structfield></entry>
|
||||||
<entry><type>int2vector</type></entry>
|
<entry><type>int2vector</type></entry>
|
||||||
<entry><literal><link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.attnum</literal></entry>
|
<entry><literal><link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.attnum</literal></entry>
|
||||||
<entry>
|
<entry>
|
||||||
@ -4342,7 +4344,7 @@
|
|||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>standistinct</structfield></entry>
|
<entry><structfield>stxndistinct</structfield></entry>
|
||||||
<entry><type>pg_ndistinct</type></entry>
|
<entry><type>pg_ndistinct</type></entry>
|
||||||
<entry></entry>
|
<entry></entry>
|
||||||
<entry>
|
<entry>
|
||||||
@ -4351,7 +4353,7 @@
|
|||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry><structfield>stadependencies</structfield></entry>
|
<entry><structfield>stxdependencies</structfield></entry>
|
||||||
<entry><type>pg_dependencies</type></entry>
|
<entry><type>pg_dependencies</type></entry>
|
||||||
<entry></entry>
|
<entry></entry>
|
||||||
<entry>
|
<entry>
|
||||||
|
@ -525,8 +525,8 @@ EXPLAIN ANALYZE SELECT * FROM t WHERE a = 1 AND b = 1;
|
|||||||
you may do this:
|
you may do this:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT staname,stadependencies FROM pg_statistic_ext WHERE staname = 's1';
|
SELECT stxname,stxdependencies FROM pg_statistic_ext WHERE stxname = 's1';
|
||||||
staname | stadependencies
|
stxname | stxdependencies
|
||||||
---------+--------------------------------------------
|
---------+--------------------------------------------
|
||||||
s1 | [{1 => 2 : 1.000000}, {2 => 1 : 1.000000}]
|
s1 | [{1 => 2 : 1.000000}, {2 => 1 : 1.000000}]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
@ -5148,7 +5148,7 @@ pg_statistics_ownercheck(Oid stat_oid, Oid roleid)
|
|||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
errmsg("statistics with OID %u do not exist", stat_oid)));
|
errmsg("statistics with OID %u do not exist", stat_oid)));
|
||||||
|
|
||||||
ownerId = ((Form_pg_statistic_ext) GETSTRUCT(tuple))->staowner;
|
ownerId = ((Form_pg_statistic_ext) GETSTRUCT(tuple))->stxowner;
|
||||||
|
|
||||||
ReleaseSysCache(tuple);
|
ReleaseSysCache(tuple);
|
||||||
|
|
||||||
|
@ -2805,7 +2805,7 @@ RemoveStatisticsExt(Oid relid, AttrNumber attnum)
|
|||||||
pgstatisticext = heap_open(StatisticExtRelationId, RowExclusiveLock);
|
pgstatisticext = heap_open(StatisticExtRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
ScanKeyInit(&key,
|
ScanKeyInit(&key,
|
||||||
Anum_pg_statistic_ext_starelid,
|
Anum_pg_statistic_ext_stxrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
BTEqualStrategyNumber, F_OIDEQ,
|
||||||
ObjectIdGetDatum(relid));
|
ObjectIdGetDatum(relid));
|
||||||
|
|
||||||
@ -2825,13 +2825,13 @@ RemoveStatisticsExt(Oid relid, AttrNumber attnum)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Decode the stakeys array and delete any stats that involve the
|
* Decode the stxkeys array and delete any stats that involve the
|
||||||
* specified column.
|
* specified column.
|
||||||
*/
|
*/
|
||||||
staForm = (Form_pg_statistic_ext) GETSTRUCT(tuple);
|
staForm = (Form_pg_statistic_ext) GETSTRUCT(tuple);
|
||||||
for (i = 0; i < staForm->stakeys.dim1; i++)
|
for (i = 0; i < staForm->stxkeys.dim1; i++)
|
||||||
{
|
{
|
||||||
if (staForm->stakeys.values[i] == attnum)
|
if (staForm->stxkeys.values[i] == attnum)
|
||||||
{
|
{
|
||||||
delete = true;
|
delete = true;
|
||||||
break;
|
break;
|
||||||
|
@ -485,9 +485,9 @@ static const ObjectPropertyType ObjectProperty[] =
|
|||||||
StatisticExtOidIndexId,
|
StatisticExtOidIndexId,
|
||||||
STATEXTOID,
|
STATEXTOID,
|
||||||
STATEXTNAMENSP,
|
STATEXTNAMENSP,
|
||||||
Anum_pg_statistic_ext_staname,
|
Anum_pg_statistic_ext_stxname,
|
||||||
Anum_pg_statistic_ext_stanamespace,
|
Anum_pg_statistic_ext_stxnamespace,
|
||||||
Anum_pg_statistic_ext_staowner,
|
Anum_pg_statistic_ext_stxowner,
|
||||||
InvalidAttrNumber, /* no ACL (same as relation) */
|
InvalidAttrNumber, /* no ACL (same as relation) */
|
||||||
ACL_KIND_STATISTICS,
|
ACL_KIND_STATISTICS,
|
||||||
true
|
true
|
||||||
@ -4936,13 +4936,13 @@ getObjectIdentityParts(const ObjectAddress *object,
|
|||||||
elog(ERROR, "cache lookup failed for statistics %u",
|
elog(ERROR, "cache lookup failed for statistics %u",
|
||||||
object->objectId);
|
object->objectId);
|
||||||
formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
|
formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
|
||||||
schema = get_namespace_name_or_temp(formStatistic->stanamespace);
|
schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
|
||||||
appendStringInfoString(&buffer,
|
appendStringInfoString(&buffer,
|
||||||
quote_qualified_identifier(schema,
|
quote_qualified_identifier(schema,
|
||||||
NameStr(formStatistic->staname)));
|
NameStr(formStatistic->stxname)));
|
||||||
if (objname)
|
if (objname)
|
||||||
*objname = list_make2(schema,
|
*objname = list_make2(schema,
|
||||||
pstrdup(NameStr(formStatistic->staname)));
|
pstrdup(NameStr(formStatistic->stxname)));
|
||||||
ReleaseSysCache(tup);
|
ReleaseSysCache(tup);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -50,13 +50,13 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
int numcols = 0;
|
int numcols = 0;
|
||||||
ObjectAddress address = InvalidObjectAddress;
|
ObjectAddress address = InvalidObjectAddress;
|
||||||
char *namestr;
|
char *namestr;
|
||||||
NameData staname;
|
NameData stxname;
|
||||||
Oid statoid;
|
Oid statoid;
|
||||||
Oid namespaceId;
|
Oid namespaceId;
|
||||||
HeapTuple htup;
|
HeapTuple htup;
|
||||||
Datum values[Natts_pg_statistic_ext];
|
Datum values[Natts_pg_statistic_ext];
|
||||||
bool nulls[Natts_pg_statistic_ext];
|
bool nulls[Natts_pg_statistic_ext];
|
||||||
int2vector *stakeys;
|
int2vector *stxkeys;
|
||||||
Relation statrel;
|
Relation statrel;
|
||||||
Relation rel;
|
Relation rel;
|
||||||
Oid relid;
|
Oid relid;
|
||||||
@ -64,7 +64,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
childobject;
|
childobject;
|
||||||
Datum types[2]; /* one for each possible type of statistics */
|
Datum types[2]; /* one for each possible type of statistics */
|
||||||
int ntypes;
|
int ntypes;
|
||||||
ArrayType *staenabled;
|
ArrayType *stxkind;
|
||||||
bool build_ndistinct;
|
bool build_ndistinct;
|
||||||
bool build_dependencies;
|
bool build_dependencies;
|
||||||
bool requested_type = false;
|
bool requested_type = false;
|
||||||
@ -73,13 +73,13 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
|
|
||||||
/* resolve the pieces of the name (namespace etc.) */
|
/* resolve the pieces of the name (namespace etc.) */
|
||||||
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
|
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
|
||||||
namestrcpy(&staname, namestr);
|
namestrcpy(&stxname, namestr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If if_not_exists was given and the statistics already exists, bail out.
|
* If if_not_exists was given and the statistics already exists, bail out.
|
||||||
*/
|
*/
|
||||||
if (SearchSysCacheExists2(STATEXTNAMENSP,
|
if (SearchSysCacheExists2(STATEXTNAMENSP,
|
||||||
PointerGetDatum(&staname),
|
PointerGetDatum(&stxname),
|
||||||
ObjectIdGetDatum(namespaceId)))
|
ObjectIdGetDatum(namespaceId)))
|
||||||
{
|
{
|
||||||
if (stmt->if_not_exists)
|
if (stmt->if_not_exists)
|
||||||
@ -184,7 +184,7 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
(errcode(ERRCODE_UNDEFINED_COLUMN),
|
||||||
errmsg("duplicate column name in statistics definition")));
|
errmsg("duplicate column name in statistics definition")));
|
||||||
|
|
||||||
stakeys = buildint2vector(attnums, numcols);
|
stxkeys = buildint2vector(attnums, numcols);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the statistics options. Currently only statistics types are
|
* Parse the statistics options. Currently only statistics types are
|
||||||
@ -226,23 +226,23 @@ CreateStatistics(CreateStatsStmt *stmt)
|
|||||||
if (build_dependencies)
|
if (build_dependencies)
|
||||||
types[ntypes++] = CharGetDatum(STATS_EXT_DEPENDENCIES);
|
types[ntypes++] = CharGetDatum(STATS_EXT_DEPENDENCIES);
|
||||||
Assert(ntypes > 0);
|
Assert(ntypes > 0);
|
||||||
staenabled = construct_array(types, ntypes, CHAROID, 1, true, 'c');
|
stxkind = construct_array(types, ntypes, CHAROID, 1, true, 'c');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Everything seems fine, so let's build the pg_statistic_ext tuple.
|
* Everything seems fine, so let's build the pg_statistic_ext tuple.
|
||||||
*/
|
*/
|
||||||
memset(values, 0, sizeof(values));
|
memset(values, 0, sizeof(values));
|
||||||
memset(nulls, false, sizeof(nulls));
|
memset(nulls, false, sizeof(nulls));
|
||||||
values[Anum_pg_statistic_ext_starelid - 1] = ObjectIdGetDatum(relid);
|
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
|
||||||
values[Anum_pg_statistic_ext_staname - 1] = NameGetDatum(&staname);
|
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
|
||||||
values[Anum_pg_statistic_ext_stanamespace - 1] = ObjectIdGetDatum(namespaceId);
|
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
|
||||||
values[Anum_pg_statistic_ext_staowner - 1] = ObjectIdGetDatum(GetUserId());
|
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(GetUserId());
|
||||||
values[Anum_pg_statistic_ext_stakeys - 1] = PointerGetDatum(stakeys);
|
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);
|
||||||
values[Anum_pg_statistic_ext_staenabled - 1] = PointerGetDatum(staenabled);
|
values[Anum_pg_statistic_ext_stxkind - 1] = PointerGetDatum(stxkind);
|
||||||
|
|
||||||
/* no statistics build yet */
|
/* no statistics build yet */
|
||||||
nulls[Anum_pg_statistic_ext_standistinct - 1] = true;
|
nulls[Anum_pg_statistic_ext_stxndistinct - 1] = true;
|
||||||
nulls[Anum_pg_statistic_ext_stadependencies - 1] = true;
|
nulls[Anum_pg_statistic_ext_stxdependencies - 1] = true;
|
||||||
|
|
||||||
/* insert it into pg_statistic_ext */
|
/* insert it into pg_statistic_ext */
|
||||||
statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
|
statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
|
||||||
@ -303,7 +303,7 @@ RemoveStatisticsById(Oid statsOid)
|
|||||||
elog(ERROR, "cache lookup failed for statistics %u", statsOid);
|
elog(ERROR, "cache lookup failed for statistics %u", statsOid);
|
||||||
|
|
||||||
statext = (Form_pg_statistic_ext) GETSTRUCT(tup);
|
statext = (Form_pg_statistic_ext) GETSTRUCT(tup);
|
||||||
relid = statext->starelid;
|
relid = statext->stxrelid;
|
||||||
|
|
||||||
rel = heap_open(relid, AccessExclusiveLock);
|
rel = heap_open(relid, AccessExclusiveLock);
|
||||||
|
|
||||||
|
@ -1293,8 +1293,8 @@ get_relation_statistics(RelOptInfo *rel, Relation relation)
|
|||||||
* wasted if no stats are actually built, but it doesn't seem worth
|
* wasted if no stats are actually built, but it doesn't seem worth
|
||||||
* troubling over that case.
|
* troubling over that case.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < staForm->stakeys.dim1; i++)
|
for (i = 0; i < staForm->stxkeys.dim1; i++)
|
||||||
keys = bms_add_member(keys, staForm->stakeys.values[i]);
|
keys = bms_add_member(keys, staForm->stxkeys.values[i]);
|
||||||
|
|
||||||
/* add one StatisticExtInfo for each kind built */
|
/* add one StatisticExtInfo for each kind built */
|
||||||
if (statext_is_kind_built(htup, STATS_EXT_NDISTINCT))
|
if (statext_is_kind_built(htup, STATS_EXT_NDISTINCT))
|
||||||
|
@ -411,7 +411,7 @@ statext_dependencies_build(int numrows, HeapTuple *rows, Bitmapset *attrs,
|
|||||||
d = (MVDependency *) palloc0(offsetof(MVDependency, attributes)
|
d = (MVDependency *) palloc0(offsetof(MVDependency, attributes)
|
||||||
+ k * sizeof(AttrNumber));
|
+ k * sizeof(AttrNumber));
|
||||||
|
|
||||||
/* copy the dependency (and keep the indexes into stakeys) */
|
/* copy the dependency (and keep the indexes into stxkeys) */
|
||||||
d->degree = degree;
|
d->degree = degree;
|
||||||
d->nattributes = k;
|
d->nattributes = k;
|
||||||
for (i = 0; i < k; i++)
|
for (i = 0; i < k; i++)
|
||||||
@ -652,7 +652,7 @@ staext_dependencies_load(Oid mvoid)
|
|||||||
elog(ERROR, "cache lookup failed for extended statistics %u", mvoid);
|
elog(ERROR, "cache lookup failed for extended statistics %u", mvoid);
|
||||||
|
|
||||||
deps = SysCacheGetAttr(STATEXTOID, htup,
|
deps = SysCacheGetAttr(STATEXTOID, htup,
|
||||||
Anum_pg_statistic_ext_stadependencies, &isnull);
|
Anum_pg_statistic_ext_stxdependencies, &isnull);
|
||||||
|
|
||||||
Assert(!isnull);
|
Assert(!isnull);
|
||||||
|
|
||||||
|
@ -145,11 +145,11 @@ statext_is_kind_built(HeapTuple htup, char type)
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case STATS_EXT_NDISTINCT:
|
case STATS_EXT_NDISTINCT:
|
||||||
attnum = Anum_pg_statistic_ext_standistinct;
|
attnum = Anum_pg_statistic_ext_stxndistinct;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATS_EXT_DEPENDENCIES:
|
case STATS_EXT_DEPENDENCIES:
|
||||||
attnum = Anum_pg_statistic_ext_stadependencies;
|
attnum = Anum_pg_statistic_ext_stxdependencies;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -175,7 +175,7 @@ fetch_statentries_for_relation(Relation pg_statext, Oid relid)
|
|||||||
* rel.
|
* rel.
|
||||||
*/
|
*/
|
||||||
ScanKeyInit(&skey,
|
ScanKeyInit(&skey,
|
||||||
Anum_pg_statistic_ext_starelid,
|
Anum_pg_statistic_ext_stxrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
BTEqualStrategyNumber, F_OIDEQ,
|
||||||
ObjectIdGetDatum(relid));
|
ObjectIdGetDatum(relid));
|
||||||
|
|
||||||
@ -195,23 +195,23 @@ fetch_statentries_for_relation(Relation pg_statext, Oid relid)
|
|||||||
entry = palloc0(sizeof(StatExtEntry));
|
entry = palloc0(sizeof(StatExtEntry));
|
||||||
entry->statOid = HeapTupleGetOid(htup);
|
entry->statOid = HeapTupleGetOid(htup);
|
||||||
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
|
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
|
||||||
entry->schema = get_namespace_name(staForm->stanamespace);
|
entry->schema = get_namespace_name(staForm->stxnamespace);
|
||||||
entry->name = pstrdup(NameStr(staForm->staname));
|
entry->name = pstrdup(NameStr(staForm->stxname));
|
||||||
for (i = 0; i < staForm->stakeys.dim1; i++)
|
for (i = 0; i < staForm->stxkeys.dim1; i++)
|
||||||
{
|
{
|
||||||
entry->columns = bms_add_member(entry->columns,
|
entry->columns = bms_add_member(entry->columns,
|
||||||
staForm->stakeys.values[i]);
|
staForm->stxkeys.values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* decode the staenabled char array into a list of chars */
|
/* decode the stxkind char array into a list of chars */
|
||||||
datum = SysCacheGetAttr(STATEXTOID, htup,
|
datum = SysCacheGetAttr(STATEXTOID, htup,
|
||||||
Anum_pg_statistic_ext_staenabled, &isnull);
|
Anum_pg_statistic_ext_stxkind, &isnull);
|
||||||
Assert(!isnull);
|
Assert(!isnull);
|
||||||
arr = DatumGetArrayTypeP(datum);
|
arr = DatumGetArrayTypeP(datum);
|
||||||
if (ARR_NDIM(arr) != 1 ||
|
if (ARR_NDIM(arr) != 1 ||
|
||||||
ARR_HASNULL(arr) ||
|
ARR_HASNULL(arr) ||
|
||||||
ARR_ELEMTYPE(arr) != CHAROID)
|
ARR_ELEMTYPE(arr) != CHAROID)
|
||||||
elog(ERROR, "staenabled is not a 1-D char array");
|
elog(ERROR, "stxkind is not a 1-D char array");
|
||||||
enabled = (char *) ARR_DATA_PTR(arr);
|
enabled = (char *) ARR_DATA_PTR(arr);
|
||||||
for (i = 0; i < ARR_DIMS(arr)[0]; i++)
|
for (i = 0; i < ARR_DIMS(arr)[0]; i++)
|
||||||
{
|
{
|
||||||
@ -231,7 +231,7 @@ fetch_statentries_for_relation(Relation pg_statext, Oid relid)
|
|||||||
/*
|
/*
|
||||||
* Using 'vacatts' of size 'nvacatts' as input data, return a newly built
|
* Using 'vacatts' of size 'nvacatts' as input data, return a newly built
|
||||||
* VacAttrStats array which includes only the items corresponding to
|
* VacAttrStats array which includes only the items corresponding to
|
||||||
* attributes indicated by 'stakeys'. If we don't have all of the per column
|
* attributes indicated by 'stxkeys'. If we don't have all of the per column
|
||||||
* stats available to compute the extended stats, then we return NULL to indicate
|
* stats available to compute the extended stats, then we return NULL to indicate
|
||||||
* to the caller that the stats should not be built.
|
* to the caller that the stats should not be built.
|
||||||
*/
|
*/
|
||||||
@ -310,21 +310,21 @@ statext_store(Relation pg_stext, Oid statOid,
|
|||||||
{
|
{
|
||||||
bytea *data = statext_ndistinct_serialize(ndistinct);
|
bytea *data = statext_ndistinct_serialize(ndistinct);
|
||||||
|
|
||||||
nulls[Anum_pg_statistic_ext_standistinct - 1] = (data == NULL);
|
nulls[Anum_pg_statistic_ext_stxndistinct - 1] = (data == NULL);
|
||||||
values[Anum_pg_statistic_ext_standistinct - 1] = PointerGetDatum(data);
|
values[Anum_pg_statistic_ext_stxndistinct - 1] = PointerGetDatum(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dependencies != NULL)
|
if (dependencies != NULL)
|
||||||
{
|
{
|
||||||
bytea *data = statext_dependencies_serialize(dependencies);
|
bytea *data = statext_dependencies_serialize(dependencies);
|
||||||
|
|
||||||
nulls[Anum_pg_statistic_ext_stadependencies - 1] = (data == NULL);
|
nulls[Anum_pg_statistic_ext_stxdependencies - 1] = (data == NULL);
|
||||||
values[Anum_pg_statistic_ext_stadependencies - 1] = PointerGetDatum(data);
|
values[Anum_pg_statistic_ext_stxdependencies - 1] = PointerGetDatum(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* always replace the value (either by bytea or NULL) */
|
/* always replace the value (either by bytea or NULL) */
|
||||||
replaces[Anum_pg_statistic_ext_standistinct - 1] = true;
|
replaces[Anum_pg_statistic_ext_stxndistinct - 1] = true;
|
||||||
replaces[Anum_pg_statistic_ext_stadependencies - 1] = true;
|
replaces[Anum_pg_statistic_ext_stxdependencies - 1] = true;
|
||||||
|
|
||||||
/* there should already be a pg_statistic_ext tuple */
|
/* there should already be a pg_statistic_ext tuple */
|
||||||
oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
|
oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
|
||||||
|
@ -134,7 +134,7 @@ statext_ndistinct_load(Oid mvoid)
|
|||||||
elog(ERROR, "cache lookup failed for statistics %u", mvoid);
|
elog(ERROR, "cache lookup failed for statistics %u", mvoid);
|
||||||
|
|
||||||
ndist = SysCacheGetAttr(STATEXTOID, htup,
|
ndist = SysCacheGetAttr(STATEXTOID, htup,
|
||||||
Anum_pg_statistic_ext_standistinct, &isnull);
|
Anum_pg_statistic_ext_stxndistinct, &isnull);
|
||||||
if (isnull)
|
if (isnull)
|
||||||
elog(ERROR,
|
elog(ERROR,
|
||||||
"requested statistic kind %c not yet built for statistics %u",
|
"requested statistic kind %c not yet built for statistics %u",
|
||||||
|
@ -1473,23 +1473,23 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
|||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
|
|
||||||
nsp = get_namespace_name(statextrec->stanamespace);
|
nsp = get_namespace_name(statextrec->stxnamespace);
|
||||||
appendStringInfo(&buf, "CREATE STATISTICS %s",
|
appendStringInfo(&buf, "CREATE STATISTICS %s",
|
||||||
quote_qualified_identifier(nsp,
|
quote_qualified_identifier(nsp,
|
||||||
NameStr(statextrec->staname)));
|
NameStr(statextrec->stxname)));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lookup the staenabled column so that we know how to handle the WITH
|
* Lookup the stxkind column so that we know how to handle the WITH
|
||||||
* clause.
|
* clause.
|
||||||
*/
|
*/
|
||||||
datum = SysCacheGetAttr(STATEXTOID, statexttup,
|
datum = SysCacheGetAttr(STATEXTOID, statexttup,
|
||||||
Anum_pg_statistic_ext_staenabled, &isnull);
|
Anum_pg_statistic_ext_stxkind, &isnull);
|
||||||
Assert(!isnull);
|
Assert(!isnull);
|
||||||
arr = DatumGetArrayTypeP(datum);
|
arr = DatumGetArrayTypeP(datum);
|
||||||
if (ARR_NDIM(arr) != 1 ||
|
if (ARR_NDIM(arr) != 1 ||
|
||||||
ARR_HASNULL(arr) ||
|
ARR_HASNULL(arr) ||
|
||||||
ARR_ELEMTYPE(arr) != CHAROID)
|
ARR_ELEMTYPE(arr) != CHAROID)
|
||||||
elog(ERROR, "staenabled is not a 1-D char array");
|
elog(ERROR, "stxkind is not a 1-D char array");
|
||||||
enabled = (char *) ARR_DATA_PTR(arr);
|
enabled = (char *) ARR_DATA_PTR(arr);
|
||||||
|
|
||||||
ndistinct_enabled = false;
|
ndistinct_enabled = false;
|
||||||
@ -1523,21 +1523,21 @@ pg_get_statisticsext_worker(Oid statextid, bool missing_ok)
|
|||||||
|
|
||||||
appendStringInfoString(&buf, " ON (");
|
appendStringInfoString(&buf, " ON (");
|
||||||
|
|
||||||
for (colno = 0; colno < statextrec->stakeys.dim1; colno++)
|
for (colno = 0; colno < statextrec->stxkeys.dim1; colno++)
|
||||||
{
|
{
|
||||||
AttrNumber attnum = statextrec->stakeys.values[colno];
|
AttrNumber attnum = statextrec->stxkeys.values[colno];
|
||||||
char *attname;
|
char *attname;
|
||||||
|
|
||||||
if (colno > 0)
|
if (colno > 0)
|
||||||
appendStringInfoString(&buf, ", ");
|
appendStringInfoString(&buf, ", ");
|
||||||
|
|
||||||
attname = get_relid_attribute_name(statextrec->starelid, attnum);
|
attname = get_relid_attribute_name(statextrec->stxrelid, attnum);
|
||||||
|
|
||||||
appendStringInfoString(&buf, quote_identifier(attname));
|
appendStringInfoString(&buf, quote_identifier(attname));
|
||||||
}
|
}
|
||||||
|
|
||||||
appendStringInfo(&buf, ") FROM %s",
|
appendStringInfo(&buf, ") FROM %s",
|
||||||
generate_relation_name(statextrec->starelid, NIL));
|
generate_relation_name(statextrec->stxrelid, NIL));
|
||||||
|
|
||||||
ReleaseSysCache(statexttup);
|
ReleaseSysCache(statexttup);
|
||||||
|
|
||||||
|
4
src/backend/utils/cache/relcache.c
vendored
4
src/backend/utils/cache/relcache.c
vendored
@ -4497,9 +4497,9 @@ RelationGetStatExtList(Relation relation)
|
|||||||
*/
|
*/
|
||||||
result = NIL;
|
result = NIL;
|
||||||
|
|
||||||
/* Prepare to scan pg_statistic_ext for entries having starelid = this rel. */
|
/* Prepare to scan pg_statistic_ext for entries having stxrelid = this rel. */
|
||||||
ScanKeyInit(&skey,
|
ScanKeyInit(&skey,
|
||||||
Anum_pg_statistic_ext_starelid,
|
Anum_pg_statistic_ext_stxrelid,
|
||||||
BTEqualStrategyNumber, F_OIDEQ,
|
BTEqualStrategyNumber, F_OIDEQ,
|
||||||
ObjectIdGetDatum(RelationGetRelid(relation)));
|
ObjectIdGetDatum(RelationGetRelid(relation)));
|
||||||
|
|
||||||
|
4
src/backend/utils/cache/syscache.c
vendored
4
src/backend/utils/cache/syscache.c
vendored
@ -731,8 +731,8 @@ static const struct cachedesc cacheinfo[] = {
|
|||||||
StatisticExtNameIndexId,
|
StatisticExtNameIndexId,
|
||||||
2,
|
2,
|
||||||
{
|
{
|
||||||
Anum_pg_statistic_ext_staname,
|
Anum_pg_statistic_ext_stxname,
|
||||||
Anum_pg_statistic_ext_stanamespace,
|
Anum_pg_statistic_ext_stxnamespace,
|
||||||
0,
|
0,
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
@ -6663,8 +6663,8 @@ getExtendedStatistics(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
int ntups;
|
int ntups;
|
||||||
int i_tableoid;
|
int i_tableoid;
|
||||||
int i_oid;
|
int i_oid;
|
||||||
int i_staname;
|
int i_stxname;
|
||||||
int i_stadef;
|
int i_stxdef;
|
||||||
|
|
||||||
/* Extended statistics were new in v10 */
|
/* Extended statistics were new in v10 */
|
||||||
if (fout->remoteVersion < 100000)
|
if (fout->remoteVersion < 100000)
|
||||||
@ -6707,11 +6707,11 @@ getExtendedStatistics(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
"SELECT "
|
"SELECT "
|
||||||
"tableoid, "
|
"tableoid, "
|
||||||
"oid, "
|
"oid, "
|
||||||
"staname, "
|
"stxname, "
|
||||||
"pg_catalog.pg_get_statisticsextdef(oid) AS stadef "
|
"pg_catalog.pg_get_statisticsextdef(oid) AS stxdef "
|
||||||
"FROM pg_statistic_ext "
|
"FROM pg_statistic_ext "
|
||||||
"WHERE starelid = '%u' "
|
"WHERE stxrelid = '%u' "
|
||||||
"ORDER BY staname", tbinfo->dobj.catId.oid);
|
"ORDER BY stxname", tbinfo->dobj.catId.oid);
|
||||||
|
|
||||||
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
|
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
|
||||||
|
|
||||||
@ -6719,8 +6719,8 @@ getExtendedStatistics(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
|
|
||||||
i_tableoid = PQfnumber(res, "tableoid");
|
i_tableoid = PQfnumber(res, "tableoid");
|
||||||
i_oid = PQfnumber(res, "oid");
|
i_oid = PQfnumber(res, "oid");
|
||||||
i_staname = PQfnumber(res, "staname");
|
i_stxname = PQfnumber(res, "stxname");
|
||||||
i_stadef = PQfnumber(res, "stadef");
|
i_stxdef = PQfnumber(res, "stxdef");
|
||||||
|
|
||||||
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
|
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
|
||||||
|
|
||||||
@ -6730,10 +6730,10 @@ getExtendedStatistics(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
|
statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
|
||||||
statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
|
statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
|
||||||
AssignDumpId(&statsextinfo[j].dobj);
|
AssignDumpId(&statsextinfo[j].dobj);
|
||||||
statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_staname));
|
statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_stxname));
|
||||||
statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
|
statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
|
||||||
statsextinfo[j].statsexttable = tbinfo;
|
statsextinfo[j].statsexttable = tbinfo;
|
||||||
statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stadef));
|
statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stxdef));
|
||||||
}
|
}
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
@ -2344,16 +2344,16 @@ describeOneTableDetails(const char *schemaname,
|
|||||||
{
|
{
|
||||||
printfPQExpBuffer(&buf,
|
printfPQExpBuffer(&buf,
|
||||||
"SELECT oid, "
|
"SELECT oid, "
|
||||||
"stanamespace::pg_catalog.regnamespace AS nsp, "
|
"stxnamespace::pg_catalog.regnamespace AS nsp, "
|
||||||
"staname, stakeys,\n"
|
"stxname, stxkeys,\n"
|
||||||
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
|
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
|
||||||
" FROM pg_catalog.unnest(stakeys) s(attnum)\n"
|
" FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
|
||||||
" JOIN pg_catalog.pg_attribute a ON (starelid = a.attrelid AND\n"
|
" JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
|
||||||
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
|
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
|
||||||
" (staenabled @> '{d}') AS ndist_enabled,\n"
|
" (stxkind @> '{d}') AS ndist_enabled,\n"
|
||||||
" (staenabled @> '{f}') AS deps_enabled\n"
|
" (stxkind @> '{f}') AS deps_enabled\n"
|
||||||
"FROM pg_catalog.pg_statistic_ext stat "
|
"FROM pg_catalog.pg_statistic_ext stat "
|
||||||
"WHERE starelid = '%s'\n"
|
"WHERE stxrelid = '%s'\n"
|
||||||
"ORDER BY 1;",
|
"ORDER BY 1;",
|
||||||
oid);
|
oid);
|
||||||
|
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201704141
|
#define CATALOG_VERSION_NO 201704171
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -184,9 +184,9 @@ DECLARE_UNIQUE_INDEX(pg_largeobject_metadata_oid_index, 2996, on pg_largeobject_
|
|||||||
|
|
||||||
DECLARE_UNIQUE_INDEX(pg_statistic_ext_oid_index, 3380, on pg_statistic_ext using btree(oid oid_ops));
|
DECLARE_UNIQUE_INDEX(pg_statistic_ext_oid_index, 3380, on pg_statistic_ext using btree(oid oid_ops));
|
||||||
#define StatisticExtOidIndexId 3380
|
#define StatisticExtOidIndexId 3380
|
||||||
DECLARE_UNIQUE_INDEX(pg_statistic_ext_name_index, 3997, on pg_statistic_ext using btree(staname name_ops, stanamespace oid_ops));
|
DECLARE_UNIQUE_INDEX(pg_statistic_ext_name_index, 3997, on pg_statistic_ext using btree(stxname name_ops, stxnamespace oid_ops));
|
||||||
#define StatisticExtNameIndexId 3997
|
#define StatisticExtNameIndexId 3997
|
||||||
DECLARE_INDEX(pg_statistic_ext_relid_index, 3379, on pg_statistic_ext using btree(starelid oid_ops));
|
DECLARE_INDEX(pg_statistic_ext_relid_index, 3379, on pg_statistic_ext using btree(stxrelid oid_ops));
|
||||||
#define StatisticExtRelidIndexId 3379
|
#define StatisticExtRelidIndexId 3379
|
||||||
|
|
||||||
DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, on pg_namespace using btree(nspname name_ops));
|
DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, on pg_namespace using btree(nspname name_ops));
|
||||||
|
@ -31,22 +31,22 @@
|
|||||||
CATALOG(pg_statistic_ext,3381)
|
CATALOG(pg_statistic_ext,3381)
|
||||||
{
|
{
|
||||||
/* These fields form the unique key for the entry: */
|
/* These fields form the unique key for the entry: */
|
||||||
Oid starelid; /* relation containing attributes */
|
Oid stxrelid; /* relation containing attributes */
|
||||||
NameData staname; /* statistics name */
|
NameData stxname; /* statistics name */
|
||||||
Oid stanamespace; /* OID of namespace containing this statistics */
|
Oid stxnamespace; /* OID of namespace containing this statistics */
|
||||||
Oid staowner; /* statistics owner */
|
Oid stxowner; /* statistics owner */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* variable-length fields start here, but we allow direct access to
|
* variable-length fields start here, but we allow direct access to
|
||||||
* stakeys
|
* stxkeys
|
||||||
*/
|
*/
|
||||||
int2vector stakeys; /* array of column keys */
|
int2vector stxkeys; /* array of column keys */
|
||||||
|
|
||||||
#ifdef CATALOG_VARLEN
|
#ifdef CATALOG_VARLEN
|
||||||
char staenabled[1] BKI_FORCE_NOT_NULL; /* statistic types
|
char stxkind[1] BKI_FORCE_NOT_NULL; /* statistic types
|
||||||
* requested to build */
|
* requested to build */
|
||||||
pg_ndistinct standistinct; /* ndistinct coefficients (serialized) */
|
pg_ndistinct stxndistinct; /* ndistinct coefficients (serialized) */
|
||||||
pg_dependencies stadependencies; /* dependencies (serialized) */
|
pg_dependencies stxdependencies; /* dependencies (serialized) */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} FormData_pg_statistic_ext;
|
} FormData_pg_statistic_ext;
|
||||||
@ -63,14 +63,14 @@ typedef FormData_pg_statistic_ext *Form_pg_statistic_ext;
|
|||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
#define Natts_pg_statistic_ext 8
|
#define Natts_pg_statistic_ext 8
|
||||||
#define Anum_pg_statistic_ext_starelid 1
|
#define Anum_pg_statistic_ext_stxrelid 1
|
||||||
#define Anum_pg_statistic_ext_staname 2
|
#define Anum_pg_statistic_ext_stxname 2
|
||||||
#define Anum_pg_statistic_ext_stanamespace 3
|
#define Anum_pg_statistic_ext_stxnamespace 3
|
||||||
#define Anum_pg_statistic_ext_staowner 4
|
#define Anum_pg_statistic_ext_stxowner 4
|
||||||
#define Anum_pg_statistic_ext_stakeys 5
|
#define Anum_pg_statistic_ext_stxkeys 5
|
||||||
#define Anum_pg_statistic_ext_staenabled 6
|
#define Anum_pg_statistic_ext_stxkind 6
|
||||||
#define Anum_pg_statistic_ext_standistinct 7
|
#define Anum_pg_statistic_ext_stxndistinct 7
|
||||||
#define Anum_pg_statistic_ext_stadependencies 8
|
#define Anum_pg_statistic_ext_stxdependencies 8
|
||||||
|
|
||||||
#define STATS_EXT_NDISTINCT 'd'
|
#define STATS_EXT_NDISTINCT 'd'
|
||||||
#define STATS_EXT_DEPENDENCIES 'f'
|
#define STATS_EXT_DEPENDENCIES 'f'
|
||||||
|
@ -525,12 +525,12 @@ ERROR: must be owner of statistics alt_stat3
|
|||||||
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
||||||
ERROR: statistics "alt_stat2" already exists in schema "alt_nsp2"
|
ERROR: statistics "alt_stat2" already exists in schema "alt_nsp2"
|
||||||
RESET SESSION AUTHORIZATION;
|
RESET SESSION AUTHORIZATION;
|
||||||
SELECT nspname, staname, rolname
|
SELECT nspname, stxname, rolname
|
||||||
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
|
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
|
||||||
WHERE s.stanamespace = n.oid AND s.staowner = a.oid
|
WHERE s.stxnamespace = n.oid AND s.stxowner = a.oid
|
||||||
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
||||||
ORDER BY nspname, staname;
|
ORDER BY nspname, stxname;
|
||||||
nspname | staname | rolname
|
nspname | stxname | rolname
|
||||||
----------+-----------+---------------------
|
----------+-----------+---------------------
|
||||||
alt_nsp1 | alt_stat2 | regress_alter_user2
|
alt_nsp1 | alt_stat2 | regress_alter_user2
|
||||||
alt_nsp1 | alt_stat3 | regress_alter_user1
|
alt_nsp1 | alt_stat3 | regress_alter_user1
|
||||||
|
@ -12,7 +12,7 @@ DROP STATISTICS ab1_a_b_stats;
|
|||||||
CREATE SCHEMA regress_schema_2;
|
CREATE SCHEMA regress_schema_2;
|
||||||
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1;
|
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1;
|
||||||
-- Let's also verify the pg_get_statisticsextdef output looks sane.
|
-- Let's also verify the pg_get_statisticsextdef output looks sane.
|
||||||
SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE staname = 'ab1_a_b_stats';
|
SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
|
||||||
pg_get_statisticsextdef
|
pg_get_statisticsextdef
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1
|
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1
|
||||||
@ -173,11 +173,11 @@ ERROR: duplicate column name in statistics definition
|
|||||||
-- correct command
|
-- correct command
|
||||||
CREATE STATISTICS s10 ON (a, b, c) FROM ndistinct;
|
CREATE STATISTICS s10 ON (a, b, c) FROM ndistinct;
|
||||||
ANALYZE ndistinct;
|
ANALYZE ndistinct;
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
staenabled | standistinct
|
stxkind | stxndistinct
|
||||||
------------+------------------------------------------------------------------------------------------------
|
---------+------------------------------------------------------------------------------------------------
|
||||||
{d,f} | [{(b 3 4), 301.000000}, {(b 3 6), 301.000000}, {(b 4 6), 301.000000}, {(b 3 4 6), 301.000000}]
|
{d,f} | [{(b 3 4), 301.000000}, {(b 3 6), 301.000000}, {(b 4 6), 301.000000}, {(b 3 4 6), 301.000000}]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- Hash Aggregate, thanks to estimates improved by the statistic
|
-- Hash Aggregate, thanks to estimates improved by the statistic
|
||||||
@ -239,11 +239,11 @@ INSERT INTO ndistinct (a, b, c, filler1)
|
|||||||
cash_words(mod(i,33)::int::money)
|
cash_words(mod(i,33)::int::money)
|
||||||
FROM generate_series(1,10000) s(i);
|
FROM generate_series(1,10000) s(i);
|
||||||
ANALYZE ndistinct;
|
ANALYZE ndistinct;
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
staenabled | standistinct
|
stxkind | stxndistinct
|
||||||
------------+----------------------------------------------------------------------------------------------------
|
---------+----------------------------------------------------------------------------------------------------
|
||||||
{d,f} | [{(b 3 4), 2550.000000}, {(b 3 6), 800.000000}, {(b 4 6), 1632.000000}, {(b 3 4 6), 10000.000000}]
|
{d,f} | [{(b 3 4), 2550.000000}, {(b 3 6), 800.000000}, {(b 4 6), 1632.000000}, {(b 3 4 6), 10000.000000}]
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- plans using Group Aggregate, thanks to using correct esimates
|
-- plans using Group Aggregate, thanks to using correct esimates
|
||||||
@ -299,10 +299,10 @@ EXPLAIN (COSTS off)
|
|||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
DROP STATISTICS s10;
|
DROP STATISTICS s10;
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
staenabled | standistinct
|
stxkind | stxndistinct
|
||||||
------------+--------------
|
---------+--------------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
-- dropping the statistics switches the plans to Hash Aggregate,
|
-- dropping the statistics switches the plans to Hash Aggregate,
|
||||||
|
@ -459,11 +459,11 @@ ALTER STATISTICS alt_stat3 SET SCHEMA alt_nsp2; -- failed (not owner)
|
|||||||
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
|
||||||
|
|
||||||
RESET SESSION AUTHORIZATION;
|
RESET SESSION AUTHORIZATION;
|
||||||
SELECT nspname, staname, rolname
|
SELECT nspname, stxname, rolname
|
||||||
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
|
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
|
||||||
WHERE s.stanamespace = n.oid AND s.staowner = a.oid
|
WHERE s.stxnamespace = n.oid AND s.stxowner = a.oid
|
||||||
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
|
||||||
ORDER BY nspname, staname;
|
ORDER BY nspname, stxname;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Text Search Dictionary
|
-- Text Search Dictionary
|
||||||
|
@ -16,7 +16,7 @@ CREATE SCHEMA regress_schema_2;
|
|||||||
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1;
|
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1;
|
||||||
|
|
||||||
-- Let's also verify the pg_get_statisticsextdef output looks sane.
|
-- Let's also verify the pg_get_statisticsextdef output looks sane.
|
||||||
SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE staname = 'ab1_a_b_stats';
|
SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE stxname = 'ab1_a_b_stats';
|
||||||
|
|
||||||
DROP STATISTICS regress_schema_2.ab1_a_b_stats;
|
DROP STATISTICS regress_schema_2.ab1_a_b_stats;
|
||||||
|
|
||||||
@ -130,8 +130,8 @@ CREATE STATISTICS s10 ON (a, b, c) FROM ndistinct;
|
|||||||
|
|
||||||
ANALYZE ndistinct;
|
ANALYZE ndistinct;
|
||||||
|
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
|
|
||||||
-- Hash Aggregate, thanks to estimates improved by the statistic
|
-- Hash Aggregate, thanks to estimates improved by the statistic
|
||||||
EXPLAIN (COSTS off)
|
EXPLAIN (COSTS off)
|
||||||
@ -161,8 +161,8 @@ INSERT INTO ndistinct (a, b, c, filler1)
|
|||||||
|
|
||||||
ANALYZE ndistinct;
|
ANALYZE ndistinct;
|
||||||
|
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
|
|
||||||
-- plans using Group Aggregate, thanks to using correct esimates
|
-- plans using Group Aggregate, thanks to using correct esimates
|
||||||
EXPLAIN (COSTS off)
|
EXPLAIN (COSTS off)
|
||||||
@ -182,8 +182,8 @@ EXPLAIN (COSTS off)
|
|||||||
|
|
||||||
DROP STATISTICS s10;
|
DROP STATISTICS s10;
|
||||||
|
|
||||||
SELECT staenabled, standistinct
|
SELECT stxkind, stxndistinct
|
||||||
FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
|
FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
|
||||||
|
|
||||||
-- dropping the statistics switches the plans to Hash Aggregate,
|
-- dropping the statistics switches the plans to Hash Aggregate,
|
||||||
-- due to under-estimates
|
-- due to under-estimates
|
||||||
|
Reference in New Issue
Block a user