<tbody>
<row>
- <entry><structfield>starelid</structfield></entry>
+ <entry><structfield>stxrelid</structfield></entry>
<entry><type>oid</type></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>
</row>
<row>
- <entry><structfield>staname</structfield></entry>
+ <entry><structfield>stxname</structfield></entry>
<entry><type>name</type></entry>
<entry></entry>
<entry>Name of the statistic.</entry>
</row>
<row>
- <entry><structfield>stanamespace</structfield></entry>
+ <entry><structfield>stxnamespace</structfield></entry>
<entry><type>oid</type></entry>
<entry><literal><link linkend="catalog-pg-namespace"><structname>pg_namespace</structname></link>.oid</literal></entry>
<entry>
</row>
<row>
- <entry><structfield>staowner</structfield></entry>
+ <entry><structfield>stxowner</structfield></entry>
<entry><type>oid</type></entry>
<entry><literal><link linkend="catalog-pg-authid"><structname>pg_authid</structname></link>.oid</literal></entry>
<entry>Owner of the statistic</entry>
</row>
<row>
- <entry><structfield>staenabled</structfield></entry>
+ <entry><structfield>stxkind</structfield></entry>
<entry><type>char[]</type></entry>
<entry></entry>
<entry>
- An array with the modes of the enabled statistic types, encoded as
- <literal>d</literal> for ndistinct coefficients.
+ An array with the modes of the enabled statistic types. Valid values
+ are:
+ <literal>d</literal> for ndistinct coefficients,
+ <literal>f</literal> for functional dependencies.
</entry>
</row>
<row>
- <entry><structfield>stakeys</structfield></entry>
+ <entry><structfield>stxkeys</structfield></entry>
<entry><type>int2vector</type></entry>
<entry><literal><link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>.attnum</literal></entry>
<entry>
</row>
<row>
- <entry><structfield>standistinct</structfield></entry>
+ <entry><structfield>stxndistinct</structfield></entry>
<entry><type>pg_ndistinct</type></entry>
<entry></entry>
<entry>
</row>
<row>
- <entry><structfield>stadependencies</structfield></entry>
+ <entry><structfield>stxdependencies</structfield></entry>
<entry><type>pg_dependencies</type></entry>
<entry></entry>
<entry>
you may do this:
<programlisting>
-SELECT staname,stadependencies FROM pg_statistic_ext WHERE staname = 's1';
- staname | stadependencies
+SELECT stxname,stxdependencies FROM pg_statistic_ext WHERE stxname = 's1';
+ stxname | stxdependencies
---------+--------------------------------------------
s1 | [{1 => 2 : 1.000000}, {2 => 1 : 1.000000}]
(1 row)
(errcode(ERRCODE_UNDEFINED_OBJECT),
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);
pgstatisticext = heap_open(StatisticExtRelationId, RowExclusiveLock);
ScanKeyInit(&key,
- Anum_pg_statistic_ext_starelid,
+ Anum_pg_statistic_ext_stxrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
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.
*/
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;
break;
StatisticExtOidIndexId,
STATEXTOID,
STATEXTNAMENSP,
- Anum_pg_statistic_ext_staname,
- Anum_pg_statistic_ext_stanamespace,
- Anum_pg_statistic_ext_staowner,
+ Anum_pg_statistic_ext_stxname,
+ Anum_pg_statistic_ext_stxnamespace,
+ Anum_pg_statistic_ext_stxowner,
InvalidAttrNumber, /* no ACL (same as relation) */
ACL_KIND_STATISTICS,
true
elog(ERROR, "cache lookup failed for statistics %u",
object->objectId);
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,
quote_qualified_identifier(schema,
- NameStr(formStatistic->staname)));
+ NameStr(formStatistic->stxname)));
if (objname)
*objname = list_make2(schema,
- pstrdup(NameStr(formStatistic->staname)));
+ pstrdup(NameStr(formStatistic->stxname)));
ReleaseSysCache(tup);
}
break;
int numcols = 0;
ObjectAddress address = InvalidObjectAddress;
char *namestr;
- NameData staname;
+ NameData stxname;
Oid statoid;
Oid namespaceId;
HeapTuple htup;
Datum values[Natts_pg_statistic_ext];
bool nulls[Natts_pg_statistic_ext];
- int2vector *stakeys;
+ int2vector *stxkeys;
Relation statrel;
Relation rel;
Oid relid;
childobject;
Datum types[2]; /* one for each possible type of statistics */
int ntypes;
- ArrayType *staenabled;
+ ArrayType *stxkind;
bool build_ndistinct;
bool build_dependencies;
bool requested_type = false;
/* resolve the pieces of the name (namespace etc.) */
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 (SearchSysCacheExists2(STATEXTNAMENSP,
- PointerGetDatum(&staname),
+ PointerGetDatum(&stxname),
ObjectIdGetDatum(namespaceId)))
{
if (stmt->if_not_exists)
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("duplicate column name in statistics definition")));
- stakeys = buildint2vector(attnums, numcols);
+ stxkeys = buildint2vector(attnums, numcols);
/*
* Parse the statistics options. Currently only statistics types are
if (build_dependencies)
types[ntypes++] = CharGetDatum(STATS_EXT_DEPENDENCIES);
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.
*/
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
- values[Anum_pg_statistic_ext_starelid - 1] = ObjectIdGetDatum(relid);
- values[Anum_pg_statistic_ext_staname - 1] = NameGetDatum(&staname);
- values[Anum_pg_statistic_ext_stanamespace - 1] = ObjectIdGetDatum(namespaceId);
- values[Anum_pg_statistic_ext_staowner - 1] = ObjectIdGetDatum(GetUserId());
- values[Anum_pg_statistic_ext_stakeys - 1] = PointerGetDatum(stakeys);
- values[Anum_pg_statistic_ext_staenabled - 1] = PointerGetDatum(staenabled);
+ values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
+ values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
+ values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
+ values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(GetUserId());
+ values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);
+ values[Anum_pg_statistic_ext_stxkind - 1] = PointerGetDatum(stxkind);
/* no statistics build yet */
- nulls[Anum_pg_statistic_ext_standistinct - 1] = true;
- nulls[Anum_pg_statistic_ext_stadependencies - 1] = true;
+ nulls[Anum_pg_statistic_ext_stxndistinct - 1] = true;
+ nulls[Anum_pg_statistic_ext_stxdependencies - 1] = true;
/* insert it into pg_statistic_ext */
statrel = heap_open(StatisticExtRelationId, RowExclusiveLock);
elog(ERROR, "cache lookup failed for statistics %u", statsOid);
statext = (Form_pg_statistic_ext) GETSTRUCT(tup);
- relid = statext->starelid;
+ relid = statext->stxrelid;
rel = heap_open(relid, AccessExclusiveLock);
* wasted if no stats are actually built, but it doesn't seem worth
* troubling over that case.
*/
- for (i = 0; i < staForm->stakeys.dim1; i++)
- keys = bms_add_member(keys, staForm->stakeys.values[i]);
+ for (i = 0; i < staForm->stxkeys.dim1; i++)
+ keys = bms_add_member(keys, staForm->stxkeys.values[i]);
/* add one StatisticExtInfo for each kind built */
if (statext_is_kind_built(htup, STATS_EXT_NDISTINCT))
d = (MVDependency *) palloc0(offsetof(MVDependency, attributes)
+ 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->nattributes = k;
for (i = 0; i < k; i++)
elog(ERROR, "cache lookup failed for extended statistics %u", mvoid);
deps = SysCacheGetAttr(STATEXTOID, htup,
- Anum_pg_statistic_ext_stadependencies, &isnull);
+ Anum_pg_statistic_ext_stxdependencies, &isnull);
Assert(!isnull);
switch (type)
{
case STATS_EXT_NDISTINCT:
- attnum = Anum_pg_statistic_ext_standistinct;
+ attnum = Anum_pg_statistic_ext_stxndistinct;
break;
case STATS_EXT_DEPENDENCIES:
- attnum = Anum_pg_statistic_ext_stadependencies;
+ attnum = Anum_pg_statistic_ext_stxdependencies;
break;
default:
* rel.
*/
ScanKeyInit(&skey,
- Anum_pg_statistic_ext_starelid,
+ Anum_pg_statistic_ext_stxrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
entry = palloc0(sizeof(StatExtEntry));
entry->statOid = HeapTupleGetOid(htup);
staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
- entry->schema = get_namespace_name(staForm->stanamespace);
- entry->name = pstrdup(NameStr(staForm->staname));
- for (i = 0; i < staForm->stakeys.dim1; i++)
+ entry->schema = get_namespace_name(staForm->stxnamespace);
+ entry->name = pstrdup(NameStr(staForm->stxname));
+ for (i = 0; i < staForm->stxkeys.dim1; i++)
{
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,
- Anum_pg_statistic_ext_staenabled, &isnull);
+ Anum_pg_statistic_ext_stxkind, &isnull);
Assert(!isnull);
arr = DatumGetArrayTypeP(datum);
if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) ||
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);
for (i = 0; i < ARR_DIMS(arr)[0]; i++)
{
/*
* Using 'vacatts' of size 'nvacatts' as input data, return a newly built
* 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
* to the caller that the stats should not be built.
*/
{
bytea *data = statext_ndistinct_serialize(ndistinct);
- nulls[Anum_pg_statistic_ext_standistinct - 1] = (data == NULL);
- values[Anum_pg_statistic_ext_standistinct - 1] = PointerGetDatum(data);
+ nulls[Anum_pg_statistic_ext_stxndistinct - 1] = (data == NULL);
+ values[Anum_pg_statistic_ext_stxndistinct - 1] = PointerGetDatum(data);
}
if (dependencies != NULL)
{
bytea *data = statext_dependencies_serialize(dependencies);
- nulls[Anum_pg_statistic_ext_stadependencies - 1] = (data == NULL);
- values[Anum_pg_statistic_ext_stadependencies - 1] = PointerGetDatum(data);
+ nulls[Anum_pg_statistic_ext_stxdependencies - 1] = (data == NULL);
+ values[Anum_pg_statistic_ext_stxdependencies - 1] = PointerGetDatum(data);
}
/* always replace the value (either by bytea or NULL) */
- replaces[Anum_pg_statistic_ext_standistinct - 1] = true;
- replaces[Anum_pg_statistic_ext_stadependencies - 1] = true;
+ replaces[Anum_pg_statistic_ext_stxndistinct - 1] = true;
+ replaces[Anum_pg_statistic_ext_stxdependencies - 1] = true;
/* there should already be a pg_statistic_ext tuple */
oldtup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
elog(ERROR, "cache lookup failed for statistics %u", mvoid);
ndist = SysCacheGetAttr(STATEXTOID, htup,
- Anum_pg_statistic_ext_standistinct, &isnull);
+ Anum_pg_statistic_ext_stxndistinct, &isnull);
if (isnull)
elog(ERROR,
"requested statistic kind %c not yet built for statistics %u",
initStringInfo(&buf);
- nsp = get_namespace_name(statextrec->stanamespace);
+ nsp = get_namespace_name(statextrec->stxnamespace);
appendStringInfo(&buf, "CREATE STATISTICS %s",
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.
*/
datum = SysCacheGetAttr(STATEXTOID, statexttup,
- Anum_pg_statistic_ext_staenabled, &isnull);
+ Anum_pg_statistic_ext_stxkind, &isnull);
Assert(!isnull);
arr = DatumGetArrayTypeP(datum);
if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) ||
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);
ndistinct_enabled = false;
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;
if (colno > 0)
appendStringInfoString(&buf, ", ");
- attname = get_relid_attribute_name(statextrec->starelid, attnum);
+ attname = get_relid_attribute_name(statextrec->stxrelid, attnum);
appendStringInfoString(&buf, quote_identifier(attname));
}
appendStringInfo(&buf, ") FROM %s",
- generate_relation_name(statextrec->starelid, NIL));
+ generate_relation_name(statextrec->stxrelid, NIL));
ReleaseSysCache(statexttup);
*/
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,
- Anum_pg_statistic_ext_starelid,
+ Anum_pg_statistic_ext_stxrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(RelationGetRelid(relation)));
StatisticExtNameIndexId,
2,
{
- Anum_pg_statistic_ext_staname,
- Anum_pg_statistic_ext_stanamespace,
+ Anum_pg_statistic_ext_stxname,
+ Anum_pg_statistic_ext_stxnamespace,
0,
0
},
int ntups;
int i_tableoid;
int i_oid;
- int i_staname;
- int i_stadef;
+ int i_stxname;
+ int i_stxdef;
/* Extended statistics were new in v10 */
if (fout->remoteVersion < 100000)
"SELECT "
"tableoid, "
"oid, "
- "staname, "
- "pg_catalog.pg_get_statisticsextdef(oid) AS stadef "
+ "stxname, "
+ "pg_catalog.pg_get_statisticsextdef(oid) AS stxdef "
"FROM pg_statistic_ext "
- "WHERE starelid = '%u' "
- "ORDER BY staname", tbinfo->dobj.catId.oid);
+ "WHERE stxrelid = '%u' "
+ "ORDER BY stxname", tbinfo->dobj.catId.oid);
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
i_tableoid = PQfnumber(res, "tableoid");
i_oid = PQfnumber(res, "oid");
- i_staname = PQfnumber(res, "staname");
- i_stadef = PQfnumber(res, "stadef");
+ i_stxname = PQfnumber(res, "stxname");
+ i_stxdef = PQfnumber(res, "stxdef");
statsextinfo = (StatsExtInfo *) pg_malloc(ntups * sizeof(StatsExtInfo));
statsextinfo[j].dobj.catId.tableoid = atooid(PQgetvalue(res, j, i_tableoid));
statsextinfo[j].dobj.catId.oid = atooid(PQgetvalue(res, j, i_oid));
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].statsexttable = tbinfo;
- statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stadef));
+ statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stxdef));
}
PQclear(res);
{
printfPQExpBuffer(&buf,
"SELECT oid, "
- "stanamespace::pg_catalog.regnamespace AS nsp, "
- "staname, stakeys,\n"
+ "stxnamespace::pg_catalog.regnamespace AS nsp, "
+ "stxname, stxkeys,\n"
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
- " FROM pg_catalog.unnest(stakeys) s(attnum)\n"
- " JOIN pg_catalog.pg_attribute a ON (starelid = a.attrelid AND\n"
+ " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
+ " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
- " (staenabled @> '{d}') AS ndist_enabled,\n"
- " (staenabled @> '{f}') AS deps_enabled\n"
+ " (stxkind @> '{d}') AS ndist_enabled,\n"
+ " (stxkind @> '{f}') AS deps_enabled\n"
"FROM pg_catalog.pg_statistic_ext stat "
- "WHERE starelid = '%s'\n"
+ "WHERE stxrelid = '%s'\n"
"ORDER BY 1;",
oid);
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201704141
+#define CATALOG_VERSION_NO 201704171
#endif
DECLARE_UNIQUE_INDEX(pg_statistic_ext_oid_index, 3380, on pg_statistic_ext using btree(oid oid_ops));
#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
-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
DECLARE_UNIQUE_INDEX(pg_namespace_nspname_index, 2684, on pg_namespace using btree(nspname name_ops));
CATALOG(pg_statistic_ext,3381)
{
/* These fields form the unique key for the entry: */
- Oid starelid; /* relation containing attributes */
- NameData staname; /* statistics name */
- Oid stanamespace; /* OID of namespace containing this statistics */
- Oid staowner; /* statistics owner */
+ Oid stxrelid; /* relation containing attributes */
+ NameData stxname; /* statistics name */
+ Oid stxnamespace; /* OID of namespace containing this statistics */
+ Oid stxowner; /* statistics owner */
/*
* 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
- char staenabled[1] BKI_FORCE_NOT_NULL; /* statistic types
+ char stxkind[1] BKI_FORCE_NOT_NULL; /* statistic types
* requested to build */
- pg_ndistinct standistinct; /* ndistinct coefficients (serialized) */
- pg_dependencies stadependencies; /* dependencies (serialized) */
+ pg_ndistinct stxndistinct; /* ndistinct coefficients (serialized) */
+ pg_dependencies stxdependencies; /* dependencies (serialized) */
#endif
} FormData_pg_statistic_ext;
* ----------------
*/
#define Natts_pg_statistic_ext 8
-#define Anum_pg_statistic_ext_starelid 1
-#define Anum_pg_statistic_ext_staname 2
-#define Anum_pg_statistic_ext_stanamespace 3
-#define Anum_pg_statistic_ext_staowner 4
-#define Anum_pg_statistic_ext_stakeys 5
-#define Anum_pg_statistic_ext_staenabled 6
-#define Anum_pg_statistic_ext_standistinct 7
-#define Anum_pg_statistic_ext_stadependencies 8
+#define Anum_pg_statistic_ext_stxrelid 1
+#define Anum_pg_statistic_ext_stxname 2
+#define Anum_pg_statistic_ext_stxnamespace 3
+#define Anum_pg_statistic_ext_stxowner 4
+#define Anum_pg_statistic_ext_stxkeys 5
+#define Anum_pg_statistic_ext_stxkind 6
+#define Anum_pg_statistic_ext_stxndistinct 7
+#define Anum_pg_statistic_ext_stxdependencies 8
#define STATS_EXT_NDISTINCT 'd'
#define STATS_EXT_DEPENDENCIES 'f'
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
ERROR: statistics "alt_stat2" already exists in schema "alt_nsp2"
RESET SESSION AUTHORIZATION;
-SELECT nspname, staname, rolname
+SELECT nspname, stxname, rolname
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')
- ORDER BY nspname, staname;
- nspname | staname | rolname
+ ORDER BY nspname, stxname;
+ nspname | stxname | rolname
----------+-----------+---------------------
alt_nsp1 | alt_stat2 | regress_alter_user2
alt_nsp1 | alt_stat3 | regress_alter_user1
CREATE SCHEMA regress_schema_2;
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.
-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
---------------------------------------------------------------------
CREATE STATISTICS regress_schema_2.ab1_a_b_stats ON (a, b) FROM ab1
-- correct command
CREATE STATISTICS s10 ON (a, b, c) FROM ndistinct;
ANALYZE ndistinct;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
- staenabled | standistinct
-------------+------------------------------------------------------------------------------------------------
- {d,f} | [{(b 3 4), 301.000000}, {(b 3 6), 301.000000}, {(b 4 6), 301.000000}, {(b 3 4 6), 301.000000}]
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
+ 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}]
(1 row)
-- Hash Aggregate, thanks to estimates improved by the statistic
cash_words(mod(i,33)::int::money)
FROM generate_series(1,10000) s(i);
ANALYZE ndistinct;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
- staenabled | standistinct
-------------+----------------------------------------------------------------------------------------------------
- {d,f} | [{(b 3 4), 2550.000000}, {(b 3 6), 800.000000}, {(b 4 6), 1632.000000}, {(b 3 4 6), 10000.000000}]
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
+ 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}]
(1 row)
-- plans using Group Aggregate, thanks to using correct esimates
(3 rows)
DROP STATISTICS s10;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
- staenabled | standistinct
-------------+--------------
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
+ stxkind | stxndistinct
+---------+--------------
(0 rows)
-- dropping the statistics switches the plans to Hash Aggregate,
ALTER STATISTICS alt_stat2 SET SCHEMA alt_nsp2; -- failed (name conflict)
RESET SESSION AUTHORIZATION;
-SELECT nspname, staname, rolname
+SELECT nspname, stxname, rolname
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')
- ORDER BY nspname, staname;
+ ORDER BY nspname, stxname;
--
-- Text Search Dictionary
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.
-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;
ANALYZE ndistinct;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
-- Hash Aggregate, thanks to estimates improved by the statistic
EXPLAIN (COSTS off)
ANALYZE ndistinct;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
-- plans using Group Aggregate, thanks to using correct esimates
EXPLAIN (COSTS off)
DROP STATISTICS s10;
-SELECT staenabled, standistinct
- FROM pg_statistic_ext WHERE starelid = 'ndistinct'::regclass;
+SELECT stxkind, stxndistinct
+ FROM pg_statistic_ext WHERE stxrelid = 'ndistinct'::regclass;
-- dropping the statistics switches the plans to Hash Aggregate,
-- due to under-estimates