|
- sta relid
+ stx relid
oid
pg_class .oid
The table that the described columns belongs to
|
- sta name
+ stx name
name
Name of the statistic.
|
- sta namespace
+ stx namespace
oid
pg_namespace .oid
|
- sta owner
+ stx owner
oid
pg_authid .oid
Owner of the statistic
|
- staenable d
+ stxkin d
char[]
- An array with the modes of the enabled statistic types, encoded as
- d for ndistinct coefficients.
+ An array with the modes of the enabled statistic types. Valid values
+ are:
+ d for ndistinct coefficients,
+ f for functional dependencies.
|
- sta keys
+ stx keys
int2vector
pg_attribute .attnum
|
- sta ndistinct
+ stx ndistinct
pg_ndistinct
|
- sta dependencies
+ stx dependencies
pg_dependencies
you may do this:
-SELECT staname,stadependencies FROM pg_statistic_ext WHERE sta name = 's1';
- staname | sta dependencies
+SELECT stxname,stxdependencies FROM pg_statistic_ext WHERE stx name = 's1';
+ stxname | stx dependencies
---------+--------------------------------------------
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))->sta owner;
+ ownerId = ((Form_pg_statistic_ext) GETSTRUCT(tuple))->stx owner;
ReleaseSysCache(tuple);
pgstatisticext = heap_open(StatisticExtRelationId, RowExclusiveLock);
ScanKeyInit(&key,
- Anum_pg_statistic_ext_sta relid,
+ Anum_pg_statistic_ext_stx relid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
int i;
/*
- * Decode the sta keys array and delete any stats that involve the
+ * Decode the stx keys array and delete any stats that involve the
* specified column.
*/
staForm = (Form_pg_statistic_ext) GETSTRUCT(tuple);
- for (i = 0; i < staForm->sta keys.dim1; i++)
+ for (i = 0; i < staForm->stx keys.dim1; i++)
{
- if (staForm->sta keys.values[i] == attnum)
+ if (staForm->stx keys.values[i] == attnum)
{
delete = true;
break;
StatisticExtOidIndexId,
STATEXTOID,
STATEXTNAMENSP,
- Anum_pg_statistic_ext_sta name,
- Anum_pg_statistic_ext_sta namespace,
- Anum_pg_statistic_ext_sta owner,
+ Anum_pg_statistic_ext_stx name,
+ Anum_pg_statistic_ext_stx namespace,
+ Anum_pg_statistic_ext_stx owner,
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->sta namespace);
+ schema = get_namespace_name_or_temp(formStatistic->stx namespace);
appendStringInfoString(&buffer,
quote_qualified_identifier(schema,
- NameStr(formStatistic->sta name)));
+ NameStr(formStatistic->stx name)));
if (objname)
*objname = list_make2(schema,
- pstrdup(NameStr(formStatistic->sta name)));
+ pstrdup(NameStr(formStatistic->stx name)));
ReleaseSysCache(tup);
}
break;
int numcols = 0;
ObjectAddress address = InvalidObjectAddress;
char *namestr;
- NameData sta name;
+ NameData stx name;
Oid statoid;
Oid namespaceId;
HeapTuple htup;
Datum values[Natts_pg_statistic_ext];
bool nulls[Natts_pg_statistic_ext];
- int2vector *sta keys;
+ int2vector *stx keys;
Relation statrel;
Relation rel;
Oid relid;
childobject;
Datum types[2]; /* one for each possible type of statistics */
int ntypes;
- ArrayType *staenable d;
+ ArrayType *stxkin d;
bool build_ndistinct;
bool build_dependencies;
bool requested_type = false;
/* resolve the pieces of the name (namespace etc.) */
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
- namestrcpy(&sta name, namestr);
+ namestrcpy(&stx name, namestr);
/*
* If if_not_exists was given and the statistics already exists, bail out.
*/
if (SearchSysCacheExists2(STATEXTNAMENSP,
- PointerGetDatum(&sta name),
+ PointerGetDatum(&stx name),
ObjectIdGetDatum(namespaceId)))
{
if (stmt->if_not_exists)
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("duplicate column name in statistics definition")));
- sta keys = buildint2vector(attnums, numcols);
+ stx keys = buildint2vector(attnums, numcols);
/*
* Parse the statistics options. Currently only statistics types are
if (build_dependencies)
types[ntypes++] = CharGetDatum(STATS_EXT_DEPENDENCIES);
Assert(ntypes > 0);
- staenable d = construct_array(types, ntypes, CHAROID, 1, true, 'c');
+ stxkin d = 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_sta relid - 1] = ObjectIdGetDatum(relid);
- values[Anum_pg_statistic_ext_staname - 1] = NameGetDatum(&sta name);
- values[Anum_pg_statistic_ext_sta namespace - 1] = ObjectIdGetDatum(namespaceId);
- values[Anum_pg_statistic_ext_sta owner - 1] = ObjectIdGetDatum(GetUserId());
- values[Anum_pg_statistic_ext_stakeys - 1] = PointerGetDatum(sta keys);
- values[Anum_pg_statistic_ext_staenabled - 1] = PointerGetDatum(staenable d);
+ values[Anum_pg_statistic_ext_stx relid - 1] = ObjectIdGetDatum(relid);
+ values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stx name);
+ values[Anum_pg_statistic_ext_stx namespace - 1] = ObjectIdGetDatum(namespaceId);
+ values[Anum_pg_statistic_ext_stx owner - 1] = ObjectIdGetDatum(GetUserId());
+ values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stx keys);
+ values[Anum_pg_statistic_ext_stxkind - 1] = PointerGetDatum(stxkin d);
/* no statistics build yet */
- nulls[Anum_pg_statistic_ext_sta ndistinct - 1] = true;
- nulls[Anum_pg_statistic_ext_sta dependencies - 1] = true;
+ nulls[Anum_pg_statistic_ext_stx ndistinct - 1] = true;
+ nulls[Anum_pg_statistic_ext_stx dependencies - 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->sta relid;
+ relid = statext->stx relid;
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->sta keys.dim1; i++)
- keys = bms_add_member(keys, staForm->sta keys.values[i]);
+ for (i = 0; i < staForm->stx keys.dim1; i++)
+ keys = bms_add_member(keys, staForm->stx keys.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 sta keys) */
+ /* copy the dependency (and keep the indexes into stx keys) */
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_sta dependencies, &isnull);
+ Anum_pg_statistic_ext_stx dependencies, &isnull);
Assert(!isnull);
switch (type)
{
case STATS_EXT_NDISTINCT:
- attnum = Anum_pg_statistic_ext_sta ndistinct;
+ attnum = Anum_pg_statistic_ext_stx ndistinct;
break;
case STATS_EXT_DEPENDENCIES:
- attnum = Anum_pg_statistic_ext_sta dependencies;
+ attnum = Anum_pg_statistic_ext_stx dependencies;
break;
default:
* rel.
*/
ScanKeyInit(&skey,
- Anum_pg_statistic_ext_sta relid,
+ Anum_pg_statistic_ext_stx relid,
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->sta namespace);
- entry->name = pstrdup(NameStr(staForm->sta name));
- for (i = 0; i < staForm->sta keys.dim1; i++)
+ entry->schema = get_namespace_name(staForm->stx namespace);
+ entry->name = pstrdup(NameStr(staForm->stx name));
+ for (i = 0; i < staForm->stx keys.dim1; i++)
{
entry->columns = bms_add_member(entry->columns,
- staForm->sta keys.values[i]);
+ staForm->stx keys.values[i]);
}
- /* decode the staenable d char array into a list of chars */
+ /* decode the stxkin d char array into a list of chars */
datum = SysCacheGetAttr(STATEXTOID, htup,
- Anum_pg_statistic_ext_staenable d, &isnull);
+ Anum_pg_statistic_ext_stxkin d, &isnull);
Assert(!isnull);
arr = DatumGetArrayTypeP(datum);
if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
- elog(ERROR, "staenable d is not a 1-D char array");
+ elog(ERROR, "stxkin d 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 'sta keys'. If we don't have all of the per column
+ * attributes indicated by 'stx keys'. 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_sta ndistinct - 1] = (data == NULL);
- values[Anum_pg_statistic_ext_sta ndistinct - 1] = PointerGetDatum(data);
+ nulls[Anum_pg_statistic_ext_stx ndistinct - 1] = (data == NULL);
+ values[Anum_pg_statistic_ext_stx ndistinct - 1] = PointerGetDatum(data);
}
if (dependencies != NULL)
{
bytea *data = statext_dependencies_serialize(dependencies);
- nulls[Anum_pg_statistic_ext_sta dependencies - 1] = (data == NULL);
- values[Anum_pg_statistic_ext_sta dependencies - 1] = PointerGetDatum(data);
+ nulls[Anum_pg_statistic_ext_stx dependencies - 1] = (data == NULL);
+ values[Anum_pg_statistic_ext_stx dependencies - 1] = PointerGetDatum(data);
}
/* always replace the value (either by bytea or NULL) */
- replaces[Anum_pg_statistic_ext_sta ndistinct - 1] = true;
- replaces[Anum_pg_statistic_ext_sta dependencies - 1] = true;
+ replaces[Anum_pg_statistic_ext_stx ndistinct - 1] = true;
+ replaces[Anum_pg_statistic_ext_stx dependencies - 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_sta ndistinct, &isnull);
+ Anum_pg_statistic_ext_stx ndistinct, &isnull);
if (isnull)
elog(ERROR,
"requested statistic kind %c not yet built for statistics %u",
initStringInfo(&buf);
- nsp = get_namespace_name(statextrec->sta namespace);
+ nsp = get_namespace_name(statextrec->stx namespace);
appendStringInfo(&buf, "CREATE STATISTICS %s",
quote_qualified_identifier(nsp,
- NameStr(statextrec->sta name)));
+ NameStr(statextrec->stx name)));
/*
- * Lookup the staenable d column so that we know how to handle the WITH
+ * Lookup the stxkin d column so that we know how to handle the WITH
* clause.
*/
datum = SysCacheGetAttr(STATEXTOID, statexttup,
- Anum_pg_statistic_ext_staenable d, &isnull);
+ Anum_pg_statistic_ext_stxkin d, &isnull);
Assert(!isnull);
arr = DatumGetArrayTypeP(datum);
if (ARR_NDIM(arr) != 1 ||
ARR_HASNULL(arr) ||
ARR_ELEMTYPE(arr) != CHAROID)
- elog(ERROR, "staenable d is not a 1-D char array");
+ elog(ERROR, "stxkin d is not a 1-D char array");
enabled = (char *) ARR_DATA_PTR(arr);
ndistinct_enabled = false;
appendStringInfoString(&buf, " ON (");
- for (colno = 0; colno < statextrec->sta keys.dim1; colno++)
+ for (colno = 0; colno < statextrec->stx keys.dim1; colno++)
{
- AttrNumber attnum = statextrec->sta keys.values[colno];
+ AttrNumber attnum = statextrec->stx keys.values[colno];
char *attname;
if (colno > 0)
appendStringInfoString(&buf, ", ");
- attname = get_relid_attribute_name(statextrec->sta relid, attnum);
+ attname = get_relid_attribute_name(statextrec->stx relid, attnum);
appendStringInfoString(&buf, quote_identifier(attname));
}
appendStringInfo(&buf, ") FROM %s",
- generate_relation_name(statextrec->sta relid, NIL));
+ generate_relation_name(statextrec->stx relid, NIL));
ReleaseSysCache(statexttup);
*/
result = NIL;
- /* Prepare to scan pg_statistic_ext for entries having sta relid = this rel. */
+ /* Prepare to scan pg_statistic_ext for entries having stx relid = this rel. */
ScanKeyInit(&skey,
- Anum_pg_statistic_ext_sta relid,
+ Anum_pg_statistic_ext_stx relid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(RelationGetRelid(relation)));
StatisticExtNameIndexId,
2,
{
- Anum_pg_statistic_ext_sta name,
- Anum_pg_statistic_ext_sta namespace,
+ Anum_pg_statistic_ext_stx name,
+ Anum_pg_statistic_ext_stx namespace,
0,
0
},
int ntups;
int i_tableoid;
int i_oid;
- int i_sta name;
- int i_sta def;
+ int i_stx name;
+ int i_stx def;
/* Extended statistics were new in v10 */
if (fout->remoteVersion < 100000)
"SELECT "
"tableoid, "
"oid, "
- "sta name, "
- "pg_catalog.pg_get_statisticsextdef(oid) AS sta def "
+ "stx name, "
+ "pg_catalog.pg_get_statisticsextdef(oid) AS stx def "
"FROM pg_statistic_ext "
- "WHERE sta relid = '%u' "
- "ORDER BY sta name", tbinfo->dobj.catId.oid);
+ "WHERE stx relid = '%u' "
+ "ORDER BY stx name", 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, "sta name");
- i_stadef = PQfnumber(res, "sta def");
+ i_stxname = PQfnumber(res, "stx name");
+ i_stxdef = PQfnumber(res, "stx def");
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_sta name));
+ statsextinfo[j].dobj.name = pg_strdup(PQgetvalue(res, j, i_stx name));
statsextinfo[j].dobj.namespace = tbinfo->dobj.namespace;
statsextinfo[j].statsexttable = tbinfo;
- statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_sta def));
+ statsextinfo[j].statsextdef = pg_strdup(PQgetvalue(res, j, i_stx def));
}
PQclear(res);
{
printfPQExpBuffer(&buf,
"SELECT oid, "
- "sta namespace::pg_catalog.regnamespace AS nsp, "
- "staname, sta keys,\n"
+ "stx namespace::pg_catalog.regnamespace AS nsp, "
+ "stxname, stx keys,\n"
" (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
- " FROM pg_catalog.unnest(sta keys) s(attnum)\n"
- " JOIN pg_catalog.pg_attribute a ON (sta relid = a.attrelid AND\n"
+ " FROM pg_catalog.unnest(stx keys) s(attnum)\n"
+ " JOIN pg_catalog.pg_attribute a ON (stx relid = a.attrelid AND\n"
" a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
- " (staenable d @> '{d}') AS ndist_enabled,\n"
- " (staenable d @> '{f}') AS deps_enabled\n"
+ " (stxkin d @> '{d}') AS ndist_enabled,\n"
+ " (stxkin d @> '{f}') AS deps_enabled\n"
"FROM pg_catalog.pg_statistic_ext stat "
- "WHERE sta relid = '%s'\n"
+ "WHERE stx relid = '%s'\n"
"ORDER BY 1;",
oid);
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 20170414 1
+#define CATALOG_VERSION_NO 20170417 1
#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, sta namespace oid_ops));
+DECLARE_UNIQUE_INDEX(pg_statistic_ext_name_index, 3997, on pg_statistic_ext using btree(stxname name_ops, stx namespace oid_ops));
#define StatisticExtNameIndexId 3997
-DECLARE_INDEX(pg_statistic_ext_relid_index, 3379, on pg_statistic_ext using btree(sta relid oid_ops));
+DECLARE_INDEX(pg_statistic_ext_relid_index, 3379, on pg_statistic_ext using btree(stx relid 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 sta relid; /* relation containing attributes */
- NameData sta name; /* statistics name */
- Oid sta namespace; /* OID of namespace containing this statistics */
- Oid sta owner; /* statistics owner */
+ Oid stx relid; /* relation containing attributes */
+ NameData stx name; /* statistics name */
+ Oid stx namespace; /* OID of namespace containing this statistics */
+ Oid stx owner; /* statistics owner */
/*
* variable-length fields start here, but we allow direct access to
- * sta keys
+ * stx keys
*/
- int2vector sta keys; /* array of column keys */
+ int2vector stx keys; /* 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 sta ndistinct; /* ndistinct coefficients (serialized) */
- pg_dependencies sta dependencies; /* dependencies (serialized) */
+ pg_ndistinct stx ndistinct; /* ndistinct coefficients (serialized) */
+ pg_dependencies stx dependencies; /* dependencies (serialized) */
#endif
} FormData_pg_statistic_ext;
* ----------------
*/
#define Natts_pg_statistic_ext 8
-#define Anum_pg_statistic_ext_sta relid 1
-#define Anum_pg_statistic_ext_sta name 2
-#define Anum_pg_statistic_ext_sta namespace 3
-#define Anum_pg_statistic_ext_sta owner 4
-#define Anum_pg_statistic_ext_sta keys 5
-#define Anum_pg_statistic_ext_staenabled 6
-#define Anum_pg_statistic_ext_sta ndistinct 7
-#define Anum_pg_statistic_ext_sta dependencies 8
+#define Anum_pg_statistic_ext_stx relid 1
+#define Anum_pg_statistic_ext_stx name 2
+#define Anum_pg_statistic_ext_stx namespace 3
+#define Anum_pg_statistic_ext_stx owner 4
+#define Anum_pg_statistic_ext_stx keys 5
+#define Anum_pg_statistic_ext_stxkind 6
+#define Anum_pg_statistic_ext_stx ndistinct 7
+#define Anum_pg_statistic_ext_stx dependencies 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, sta name, rolname
+SELECT nspname, stx name, rolname
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
- WHERE s.stanamespace = n.oid AND s.sta owner = a.oid
+ WHERE s.stxnamespace = n.oid AND s.stx owner = a.oid
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
- ORDER BY nspname, sta name;
- nspname | sta name | rolname
+ ORDER BY nspname, stx name;
+ nspname | stx name | 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 sta name = 'ab1_a_b_stats';
+SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE stx name = '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, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
- staenabled | sta ndistinct
------------- +------------------------------------------------------------------------------------------------
- {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, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
+ stxkind | stx ndistinct
+---------+------------------------------------------------------------------------------------------------
+ {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, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
- staenabled | sta ndistinct
------------- +----------------------------------------------------------------------------------------------------
- {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, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
+ stxkind | stx ndistinct
+---------+----------------------------------------------------------------------------------------------------
+ {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, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
- staenabled | sta ndistinct
------------- +--------------
+SELECT stxkind, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
+ stxkind | stx ndistinct
+---------+--------------
(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, sta name, rolname
+SELECT nspname, stx name, rolname
FROM pg_statistic_ext s, pg_namespace n, pg_authid a
- WHERE s.stanamespace = n.oid AND s.sta owner = a.oid
+ WHERE s.stxnamespace = n.oid AND s.stx owner = a.oid
AND n.nspname in ('alt_nsp1', 'alt_nsp2')
- ORDER BY nspname, sta name;
+ ORDER BY nspname, stx name;
--
-- 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 sta name = 'ab1_a_b_stats';
+SELECT pg_get_statisticsextdef(oid) FROM pg_statistic_ext WHERE stx name = 'ab1_a_b_stats';
DROP STATISTICS regress_schema_2.ab1_a_b_stats;
ANALYZE ndistinct;
-SELECT staenabled, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
+SELECT stxkind, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
-- Hash Aggregate, thanks to estimates improved by the statistic
EXPLAIN (COSTS off)
ANALYZE ndistinct;
-SELECT staenabled, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
+SELECT stxkind, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
-- plans using Group Aggregate, thanks to using correct esimates
EXPLAIN (COSTS off)
DROP STATISTICS s10;
-SELECT staenabled, sta ndistinct
- FROM pg_statistic_ext WHERE sta relid = 'ndistinct'::regclass;
+SELECT stxkind, stx ndistinct
+ FROM pg_statistic_ext WHERE stx relid = 'ndistinct'::regclass;
-- dropping the statistics switches the plans to Hash Aggregate,
-- due to under-estimates