aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/statistics/dependencies.c23
-rw-r--r--src/backend/statistics/mvdistinct.c15
-rw-r--r--src/test/regress/expected/stats_ext.out12
3 files changed, 23 insertions, 27 deletions
diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c
index 0890514bf78..fe9a9ef5de0 100644
--- a/src/backend/statistics/dependencies.c
+++ b/src/backend/statistics/dependencies.c
@@ -624,7 +624,7 @@ dependency_is_fully_matched(MVDependency * dependency, Bitmapset *attnums)
* 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;
@@ -641,11 +641,6 @@ staext_dependencies_load(Oid mvoid)
{
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))
@@ -653,7 +648,6 @@ staext_dependencies_load(Oid mvoid)
deps = SysCacheGetAttr(STATEXTOID, htup,
Anum_pg_statistic_ext_stxdependencies, &isnull);
-
Assert(!isnull);
ReleaseSysCache(htup);
@@ -687,16 +681,14 @@ pg_dependencies_in(PG_FUNCTION_ARGS)
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++)
{
@@ -705,7 +697,7 @@ pg_dependencies_out(PG_FUNCTION_ARGS)
if (i > 0)
appendStringInfoString(&str, ", ");
- appendStringInfoChar(&str, '{');
+ appendStringInfoChar(&str, '"');
for (j = 0; j < dependency->nattributes; j++)
{
if (j == dependency->nattributes - 1)
@@ -715,11 +707,10 @@ pg_dependencies_out(PG_FUNCTION_ARGS)
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);
}
diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.c
index b77113fb393..f67f5762360 100644
--- a/src/backend/statistics/mvdistinct.c
+++ b/src/backend/statistics/mvdistinct.c
@@ -354,21 +354,26 @@ pg_ndistinct_out(PG_FUNCTION_ARGS)
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);
}
diff --git a/src/test/regress/expected/stats_ext.out b/src/test/regress/expected/stats_ext.out
index 72b1014195d..92ac84ac671 100644
--- a/src/test/regress/expected/stats_ext.out
+++ b/src/test/regress/expected/stats_ext.out
@@ -175,9 +175,9 @@ CREATE STATISTICS s10 ON (a, b, c) FROM ndistinct;
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
@@ -241,9 +241,9 @@ INSERT INTO ndistinct (a, b, c, filler1)
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