Skip to content

Commit a171250

Browse files
committed
Fix core dump generated by "ORCA support ext stats, Fix EPQ..."
There are two parts in the current cherry-pick that need to be adapted: 1. In CBDB, the `rel->rd_partdesc` cannot be used as a basis for determining that current table is a partition table or not. 2. `get_relation_statistics` implementation has changed.
1 parent cdf1754 commit a171250

File tree

6 files changed

+31
-26
lines changed

6 files changed

+31
-26
lines changed

src/backend/gpopt/gpdbwrappers.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,17 @@ gpdb::GetRelationPartitionKey(Relation rel)
870870
return nullptr;
871871
}
872872

873+
PartitionDesc
874+
gpdb::RelationGetPartitionDesc(Relation rel, bool omit_detached)
875+
{
876+
GP_WRAP_START;
877+
{
878+
return ::RelationGetPartitionDesc(rel, omit_detached);
879+
}
880+
GP_WRAP_END;
881+
return nullptr;
882+
}
883+
873884
bool
874885
gpdb::GetCastFunc(Oid src_oid, Oid dest_oid, bool *is_binary_coercible,
875886
Oid *cast_fn_oid, CoercionPathType *pathtype)

src/backend/gpopt/translate/CPartPruneStepsBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CPartPruneStepsBuilder::CreatePartPruneInfoForOneLevel(CDXLNode *filterNode)
7272
PartitionedRelPruneInfo *pinfo = MakeNode(PartitionedRelPruneInfo);
7373
pinfo->rtindex = m_rtindex;
7474

75-
pinfo->nparts = RelationGetPartitionDesc(m_relation, true)->nparts;
75+
pinfo->nparts = gpdb::RelationGetPartitionDesc(m_relation, true)->nparts;
7676

7777
pinfo->subpart_map = (int *) palloc(sizeof(int) * pinfo->nparts);
7878
pinfo->subplan_map = (int *) palloc(sizeof(int) * pinfo->nparts);
@@ -90,7 +90,7 @@ CPartPruneStepsBuilder::CreatePartPruneInfoForOneLevel(CDXLNode *filterNode)
9090
{
9191
// partition did survive pruning
9292
pinfo->subplan_map[i] = part_ptr;
93-
pinfo->relid_map[i] = RelationGetPartitionDesc(m_relation, true)->oids[i];
93+
pinfo->relid_map[i] = gpdb::RelationGetPartitionDesc(m_relation, true)->oids[i];
9494
pinfo->present_parts = bms_add_member(pinfo->present_parts, i);
9595
++part_ptr;
9696
}

src/backend/gpopt/translate/CTranslatorRelcacheToDXL.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ CTranslatorRelcacheToDXL::RetrieveRelCheckConstraints(CMemoryPool *mp, OID oid)
320320
void
321321
CTranslatorRelcacheToDXL::CheckUnsupportedRelation(Relation rel)
322322
{
323-
if (!rel->rd_partdesc && gpdb::HasSubclassSlow(rel->rd_id))
323+
if (!gpdb::RelationGetPartitionDesc(rel, true) && gpdb::HasSubclassSlow(rel->rd_id))
324324
{
325325
GPOS_RAISE(gpdxl::ExmaMD, gpdxl::ExmiMDObjUnsupported,
326326
GPOS_WSZ_LIT("Inherited tables"));
@@ -374,11 +374,10 @@ CTranslatorRelcacheToDXL::RetrieveExtStats(CMemoryPool *mp, IMDId *mdid)
374374

375375
CBitSet *attnos = GPOS_NEW(mp) CBitSet(mp);
376376

377-
int attno = -1;
378-
while ((attno = bms_next_member(item.attrs, attno)) >= 0)
379-
{
380-
attnos->ExchangeSet(attno);
377+
for (int item_idx = 0; item_idx < item.nattributes; item_idx++) {
378+
attnos->ExchangeSet(item.attributes[item_idx]);
381379
}
380+
382381
md_ndistincts->Append(GPOS_NEW(mp)
383382
CMDNDistinct(mp, item.ndistinct, attnos));
384383
}
@@ -552,17 +551,18 @@ CTranslatorRelcacheToDXL::RetrieveRel(CMemoryPool *mp, CMDAccessor *md_accessor,
552551
is_partitioned = (nullptr != part_keys && 0 < part_keys->Size());
553552

554553
// get number of leaf partitions
555-
if (rel->rd_partdesc)
554+
PartitionDesc part_desc = gpdb::RelationGetPartitionDesc(rel.get(), true);
555+
if (part_desc)
556556
{
557557
partition_oids = GPOS_NEW(mp) IMdIdArray(mp);
558558

559-
for (int i = 0; i < RelationGetPartitionDesc(rel.get(), true)->nparts; ++i)
559+
for (int i = 0; i < part_desc->nparts; ++i)
560560
{
561-
Oid oid = RelationGetPartitionDesc(rel.get(), true)->oids[i];
561+
Oid oid = part_desc->oids[i];
562562
partition_oids->Append(GPOS_NEW(mp)
563563
CMDIdGPDB(IMDId::EmdidRel, oid));
564564
gpdb::RelationWrapper rel_part = gpdb::GetRelation(oid);
565-
if (rel_part->rd_partdesc)
565+
if (gpdb::RelationGetPartitionDesc(rel_part.get(), true))
566566
{
567567
// Multi-level partitioned tables are unsupported - fall back
568568
GPOS_RAISE(gpdxl::ExmaMD, gpdxl::ExmiMDObjUnsupported,
@@ -3007,13 +3007,13 @@ CTranslatorRelcacheToDXL::RetrieveStorageTypeForPartitionedTable(Relation rel)
30073007
// causes gporca generate another query plan. The problem is that the CWorkerPoolManager
30083008
// holds a static worker pointer, executing gporca nestly is not supported now.
30093009
// See CWorkerPoolManager::RegisterWorker()
3010-
if (RelationGetPartitionDesc(rel, true)->nparts == 0)
3010+
if (gpdb::RelationGetPartitionDesc(rel, true)->nparts == 0)
30113011
{
30123012
return IMDRelation::ErelstorageHeap;
30133013
}
3014-
for (int i = 0; i < RelationGetPartitionDesc(rel, true)->nparts; ++i)
3014+
for (int i = 0; i < gpdb::RelationGetPartitionDesc(rel, true)->nparts; ++i)
30153015
{
3016-
Oid oid = RelationGetPartitionDesc(rel, true)->oids[i];
3016+
Oid oid = gpdb::RelationGetPartitionDesc(rel, true)->oids[i];
30173017
gpdb::RelationWrapper child_rel = gpdb::GetRelation(oid);
30183018
IMDRelation::Erelstoragetype child_storage =
30193019
RetrieveRelStorageType(child_rel.get());

src/backend/nodes/readfuncs.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,14 +2382,6 @@ ReadCommonSort(Sort *local_node)
23822382
READ_BOOL_ARRAY(nullsFirst, local_node->numCols);
23832383
}
23842384

2385-
static void
2386-
ReadSort(Sort *local_node)
2387-
{
2388-
READ_TEMP_LOCALS();
2389-
2390-
ReadCommonSort(local_node);
2391-
}
2392-
23932385
/*
23942386
* _readSort
23952387
*/
@@ -2398,7 +2390,7 @@ _readSort(void)
23982390
{
23992391
READ_LOCALS_NO_FIELDS(Sort);
24002392

2401-
ReadSort(local_node);
2393+
ReadCommonSort(local_node);
24022394

24032395
READ_DONE();
24042396
}
@@ -2411,7 +2403,7 @@ _readIncrementalSort(void)
24112403
{
24122404
READ_LOCALS(IncrementalSort);
24132405

2414-
ReadSort(&local_node->sort);
2406+
ReadCommonSort(&local_node->sort);
24152407

24162408
READ_INT_FIELD(nPresortedCols);
24172409

src/backend/optimizer/util/plancat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ GetRelationExtStatistics(Relation relation)
16201620
static List *
16211621
get_relation_statistics(RelOptInfo *rel, Relation relation)
16221622
{
1623-
Index varno = rel->relid;
1623+
Index varno = rel ? rel->relid : 0;
16241624
List *statoidlist;
16251625
List *stainfos = NIL;
16261626
ListCell *l;
@@ -1658,7 +1658,7 @@ get_relation_statistics(RelOptInfo *rel, Relation relation)
16581658
* Preprocess expressions (if any). We read the expressions, run them
16591659
* through eval_const_expressions, and fix the varnos.
16601660
*/
1661-
{
1661+
if (rel) {
16621662
bool isnull;
16631663
Datum datum;
16641664

src/include/gpopt/gpdbwrappers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ void BuildRelationTriggers(Relation rel);
516516

517517
PartitionKey GetRelationPartitionKey(Relation rel);
518518

519+
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached);
520+
519521
MVNDistinct *GetMVNDistinct(Oid stat_oid);
520522

521523
MVDependencies *GetMVDependencies(Oid stat_oid);

0 commit comments

Comments
 (0)