SELECT stxname, stxkeys, stxdependencies
FROM pg_statistic_ext
WHERE stxname = 'stts';
- stxname | stxkeys | stxdependencies
----------+---------+--------------------------------------------
- stts | 1 5 | [{1 => 5 : 1.000000}, {5 => 1 : 0.423130}]
+ stxname | stxkeys | stxdependencies
+---------+---------+------------------------------------------
+ stts | 1 5 | {"1 => 5": 1.000000, "5 => 1": 0.423130}
(1 row)
</programlisting>
where it can be seen that column 1 (a zip code) fully determines column
SELECT stxkeys AS k, stxndistinct AS nd
FROM pg_statistic_ext
WHERE stxname = 'stts2';
--[ RECORD 1 ]---------------------------------------------
+-[ RECORD 1 ]--------------------------------------------------------
k | 1 2 5
-nd | [{(b 1 2), 33178.000000}, {(b 1 5), 33178.000000},
- {(b 2 5), 27435.000000}, {(b 1 2 5), 33178.000000}]
+nd | {"1, 2": 33178, "1, 5": 33178, "2, 5": 27435, "1, 2, 5": 33178}
(1 row)
</programlisting>
which indicates that there are three combinations of columns that
* check that the attnum matches is implied by the functional dependency
*/
static bool
-dependency_implies_attribute(MVDependency * dependency, AttrNumber attnum)
+dependency_implies_attribute(MVDependency *dependency, AttrNumber attnum)
{
if (attnum == dependency->attributes[dependency->nattributes - 1])
return true;
{
bool isnull;
Datum deps;
-
- /*
- * Prepare to scan pg_statistic_ext for entries having indrelid = this
- * rel.
- */
HeapTuple htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid));
if (!HeapTupleIsValid(htup))
deps = SysCacheGetAttr(STATEXTOID, htup,
Anum_pg_statistic_ext_stxdependencies, &isnull);
-
Assert(!isnull);
ReleaseSysCache(htup);
Datum
pg_dependencies_out(PG_FUNCTION_ARGS)
{
+ bytea *data = PG_GETARG_BYTEA_PP(0);
+ MVDependencies *dependencies = statext_dependencies_deserialize(data);
int i,
j;
StringInfoData str;
- bytea *data = PG_GETARG_BYTEA_PP(0);
-
- MVDependencies *dependencies = statext_dependencies_deserialize(data);
-
initStringInfo(&str);
- appendStringInfoChar(&str, '[');
+ appendStringInfoChar(&str, '{');
for (i = 0; i < dependencies->ndeps; i++)
{
if (i > 0)
appendStringInfoString(&str, ", ");
- appendStringInfoChar(&str, '{');
+ appendStringInfoChar(&str, '"');
for (j = 0; j < dependency->nattributes; j++)
{
if (j == dependency->nattributes - 1)
appendStringInfo(&str, "%d", dependency->attributes[j]);
}
- appendStringInfo(&str, " : %f", dependency->degree);
- appendStringInfoChar(&str, '}');
+ appendStringInfo(&str, "\": %f", dependency->degree);
}
- appendStringInfoChar(&str, ']');
+ appendStringInfoChar(&str, '}');
PG_RETURN_CSTRING(str.data);
}
StringInfoData str;
initStringInfo(&str);
- appendStringInfoChar(&str, '[');
+ appendStringInfoChar(&str, '{');
for (i = 0; i < ndist->nitems; i++)
{
MVNDistinctItem item = ndist->items[i];
+ int x = -1;
+ bool first = true;
if (i > 0)
appendStringInfoString(&str, ", ");
- appendStringInfoChar(&str, '{');
- outBitmapset(&str, item.attrs);
- appendStringInfo(&str, ", %f}", item.ndistinct);
+ while ((x = bms_next_member(item.attrs, x)) >= 0)
+ {
+ appendStringInfo(&str, "%s%d", first ? "\"" : ", ", x);
+ first = false;
+ }
+ appendStringInfo(&str, "\": %d", (int) item.ndistinct);
}
- appendStringInfoChar(&str, ']');
+ appendStringInfoChar(&str, '}');
PG_RETURN_CSTRING(str.data);
}
ANALYZE ndistinct;
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}]
+ stxkind | stxndistinct
+---------+---------------------------------------------------------
+ {d,f} | {"3, 4": 301, "3, 6": 301, "4, 6": 301, "3, 4, 6": 301}
(1 row)
-- Hash Aggregate, thanks to estimates improved by the statistic
ANALYZE ndistinct;
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}]
+ stxkind | stxndistinct
+---------+-------------------------------------------------------------
+ {d,f} | {"3, 4": 2550, "3, 6": 800, "4, 6": 1632, "3, 4, 6": 10000}
(1 row)
-- plans using Group Aggregate, thanks to using correct esimates