diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index ae0f304dba5..99975817de9 100644 --- a/src/backend/statistics/dependencies.c +++ b/src/backend/statistics/dependencies.c @@ -631,20 +631,27 @@ dependency_implies_attribute(MVDependency *dependency, AttrNumber attnum) MVDependencies * statext_dependencies_load(Oid mvoid) { + MVDependencies *result; bool isnull; Datum deps; - HeapTuple htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid)); + HeapTuple htup; + htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid)); if (!HeapTupleIsValid(htup)) elog(ERROR, "cache lookup failed for statistics object %u", mvoid); deps = SysCacheGetAttr(STATEXTOID, htup, Anum_pg_statistic_ext_stxdependencies, &isnull); - Assert(!isnull); + if (isnull) + elog(ERROR, + "requested statistic kind \"%c\" is not yet built for statistics object %u", + STATS_EXT_DEPENDENCIES, mvoid); + + result = statext_dependencies_deserialize(DatumGetByteaPP(deps)); ReleaseSysCache(htup); - return statext_dependencies_deserialize(DatumGetByteaP(deps)); + return result; } /* diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.c index 913829233ec..74ab62d91a8 100644 --- a/src/backend/statistics/mvdistinct.c +++ b/src/backend/statistics/mvdistinct.c @@ -126,24 +126,27 @@ statext_ndistinct_build(double totalrows, int numrows, HeapTuple *rows, MVNDistinct * statext_ndistinct_load(Oid mvoid) { - bool isnull = false; + MVNDistinct *result; + bool isnull; Datum ndist; HeapTuple htup; htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(mvoid)); - if (!htup) + if (!HeapTupleIsValid(htup)) elog(ERROR, "cache lookup failed for statistics object %u", mvoid); ndist = SysCacheGetAttr(STATEXTOID, htup, Anum_pg_statistic_ext_stxndistinct, &isnull); if (isnull) elog(ERROR, - "requested statistic kind %c is not yet built for statistics object %u", + "requested statistic kind \"%c\" is not yet built for statistics object %u", STATS_EXT_NDISTINCT, mvoid); + result = statext_ndistinct_deserialize(DatumGetByteaPP(ndist)); + ReleaseSysCache(htup); - return statext_ndistinct_deserialize(DatumGetByteaP(ndist)); + return result; } /*