Skip to content

Commit 7feb5b7

Browse files
committed
ORCA: guard RetrieveExtStatsInfo against dropped statistics OID
When a DROP STATISTICS (or ALTER TABLE DROP COLUMN) drops a statistics object within the same transaction, the relation's rd_statlist can still contain a stale StatisticExtInfo entry whose backing pg_statistic_ext row is already gone. RetrieveExtStatsInfo iterated over that list and called gpdb::GetExtStatsName(info->statOid) without checking for a NULL return. GetExtStatsName returns NULL for a missing OID. Passing NULL straight into CDXLUtils::CreateDynamicStringFromCharArray triggers an assertion failure in debug builds and undefined behaviour (corrupt memory) in release builds, which in turn caused seemingly unrelated crashes later in the same query — most visibly a SIGSEGV inside CMDKey::UlHashMDKey called from Ptabdesc → RetrieveType when optimising an INSERT. Fix: skip any StatisticExtInfo entry whose name cannot be resolved, consistent with the same guard added to RetrieveExtStats in the previous commit.
1 parent 03d2338 commit 7feb5b7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,17 @@ CTranslatorRelcacheToDXL::RetrieveExtStatsInfo(CMemoryPool *mp, IMDId *mdid)
573573
continue;
574574
}
575575

576+
/* Guard against a stale rd_statlist entry whose backing pg_statistic_ext
577+
* row was already removed (e.g. DROP STATISTICS in the same transaction).
578+
* Skip silently so ORCA still sees the other valid statistics. */
579+
char *raw_statname = gpdb::GetExtStatsName(info->statOid);
580+
if (nullptr == raw_statname)
581+
{
582+
continue;
583+
}
576584
const CWStringConst *statname = GPOS_NEW(mp)
577585
CWStringConst(CDXLUtils::CreateDynamicStringFromCharArray(
578-
mp, gpdb::GetExtStatsName(info->statOid))
586+
mp, raw_statname)
579587
->GetBuffer());
580588
CMDName *mdname = GPOS_NEW(mp) CMDName(mp, statname);
581589

0 commit comments

Comments
 (0)