diff --git a/src/backend/gpopt/gpdbwrappers.cpp b/src/backend/gpopt/gpdbwrappers.cpp index b00b03d177f..61c5f73b331 100644 --- a/src/backend/gpopt/gpdbwrappers.cpp +++ b/src/backend/gpopt/gpdbwrappers.cpp @@ -1929,7 +1929,7 @@ gpdb::GetMVDependencies(Oid stat_oid) { GP_WRAP_START; { - return statext_dependencies_load(stat_oid); + return statext_dependencies_load(stat_oid, true); } GP_WRAP_END; } diff --git a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp index 4f3940fbf22..4eecea5cea6 100644 --- a/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp +++ b/src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp @@ -345,21 +345,24 @@ CTranslatorRelcacheToDXL::RetrieveExtStats(CMemoryPool *mp, IMDId *mdid) if (list_member_int(kinds, STATS_EXT_DEPENDENCIES)) { MVDependencies *dependencies = gpdb::GetMVDependencies(stat_oid); + // dependencies can be null after analyzed. + if (dependencies) { - for (ULONG i = 0; i < dependencies->ndeps; i++) - { - MVDependency *dep = dependencies->deps[i]; - - // Note: MVDependency->attributes's last index is the dependent "to" - // column. - IntPtrArray *from_attnos = GPOS_NEW(mp) IntPtrArray(mp); - for (INT j = 0; j < dep->nattributes - 1; j++) + for (ULONG i = 0; i < dependencies->ndeps; i++) { - from_attnos->Append(GPOS_NEW(mp) INT(dep->attributes[j])); + MVDependency *dep = dependencies->deps[i]; + + // Note: MVDependency->attributes's last index is the dependent "to" + // column. + IntPtrArray *from_attnos = GPOS_NEW(mp) IntPtrArray(mp); + for (INT j = 0; j < dep->nattributes - 1; j++) + { + from_attnos->Append(GPOS_NEW(mp) INT(dep->attributes[j])); + } + deps->Append(GPOS_NEW(mp) CMDDependency( + mp, dep->degree, from_attnos, + dep->attributes[dep->nattributes - 1])); } - deps->Append(GPOS_NEW(mp) CMDDependency( - mp, dep->degree, from_attnos, - dep->attributes[dep->nattributes - 1])); } } @@ -442,12 +445,22 @@ CTranslatorRelcacheToDXL::RetrieveExtStatsInfo(CMemoryPool *mp, IMDId *mdid) statkind = CMDExtStatsInfo::EstatMCV; break; } + case STATS_EXT_EXPRESSIONS: + { + statkind = CMDExtStatsInfo::EstatExpr; + break; + } default: { GPOS_ASSERT(false && "Unknown extended stat type"); } } + // CBDB_MERGE_FIXME: support expr ext stats in the feature + if (statkind == CMDExtStatsInfo::EstatExpr) { + continue; + } + const CWStringConst *statname = GPOS_NEW(mp) CWStringConst(CDXLUtils::CreateDynamicStringFromCharArray( mp, gpdb::GetExtStatsName(info->statOid)) diff --git a/src/backend/gporca/libnaucrates/include/naucrates/md/CMDExtStatsInfo.h b/src/backend/gporca/libnaucrates/include/naucrates/md/CMDExtStatsInfo.h index fcb9d385751..fb2e6878a79 100644 --- a/src/backend/gporca/libnaucrates/include/naucrates/md/CMDExtStatsInfo.h +++ b/src/backend/gporca/libnaucrates/include/naucrates/md/CMDExtStatsInfo.h @@ -42,6 +42,7 @@ class CMDExtStatsInfo : public CRefCount EstatDependencies, EstatNDistinct, EstatMCV, + EstatExpr, EstatSentinel }; diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index 9482b108066..8b3d560cb20 100644 --- a/src/backend/statistics/dependencies.c +++ b/src/backend/statistics/dependencies.c @@ -619,7 +619,7 @@ dependency_is_fully_matched(MVDependency *dependency, Bitmapset *attnums) * Load the functional dependencies for the indicated pg_statistic_ext tuple */ MVDependencies * -statext_dependencies_load(Oid mvoid) +statext_dependencies_load(Oid mvoid, bool allow_null) { MVDependencies *result; bool isnull; @@ -633,9 +633,17 @@ statext_dependencies_load(Oid mvoid) deps = SysCacheGetAttr(STATEXTDATASTXOID, htup, Anum_pg_statistic_ext_data_stxddependencies, &isnull); if (isnull) - elog(ERROR, - "requested statistics kind \"%c\" is not yet built for statistics object %u", - STATS_EXT_DEPENDENCIES, mvoid); + { + if (!allow_null) + { + elog(ERROR, + "requested statistics kind \"%c\" is not yet built for statistics object %u", + STATS_EXT_DEPENDENCIES, mvoid); + } + + ReleaseSysCache(htup); + return NULL; + } result = statext_dependencies_deserialize(DatumGetByteaPP(deps)); @@ -1656,7 +1664,7 @@ dependencies_clauselist_selectivity(PlannerInfo *root, if (nmatched + nexprs < 2) continue; - deps = statext_dependencies_load(stat->statOid); + deps = statext_dependencies_load(stat->statOid, false); /* * The expressions may be represented by different attnums in the diff --git a/src/include/statistics/statistics.h b/src/include/statistics/statistics.h index 326cf26feae..a4166112c98 100644 --- a/src/include/statistics/statistics.h +++ b/src/include/statistics/statistics.h @@ -95,7 +95,7 @@ typedef struct MCVList } MCVList; extern MVNDistinct *statext_ndistinct_load(Oid mvoid); -extern MVDependencies *statext_dependencies_load(Oid mvoid); +extern MVDependencies *statext_dependencies_load(Oid mvoid, bool allow_null); extern MCVList *statext_mcv_load(Oid mvoid); extern void BuildRelationExtStatistics(Relation onerel, double totalrows,