Skip to content

Commit

Permalink
Save segments number instead of list of them
Browse files Browse the repository at this point in the history
  • Loading branch information
dnskvlnk committed Nov 28, 2023
1 parent d230229 commit cd341ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class CExpression : public CRefCount, public gpos::DbgPrintMixin<CExpression>
CDrvdProp *Pdp(const CDrvdProp::EPropType ept) const;

// parent motion's input segments
IntPtrArray *m_motionInputSegments;
ULONG m_motionInputSegmentsNumber;

#ifdef GPOS_DEBUG

Expand Down Expand Up @@ -219,18 +219,18 @@ class CExpression : public CRefCount, public gpos::DbgPrintMixin<CExpression>
return m_cost;
}

void SetMotionInputsForChildren();
void SetMotionInputsNumberForChildren();

void
SetMotionInputs(IntPtrArray *motionInputSegments)
SetMotionInputsNumber(ULONG motionInputSegmentsNumber)
{
m_motionInputSegments = motionInputSegments;
m_motionInputSegmentsNumber = motionInputSegmentsNumber;
}

IntPtrArray *
GetMotionInputs() const
ULONG
GetMotionInputsNumber() const
{
return m_motionInputSegments;
return m_motionInputSegmentsNumber;
}

// get the suitable derived property type based on operator
Expand Down
16 changes: 8 additions & 8 deletions src/backend/gporca/libgpopt/src/operators/CExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop,
m_cost(GPOPT_INVALID_COST),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -104,7 +104,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop, CExpression *pexpr)
m_cost(GPOPT_INVALID_COST),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -142,7 +142,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop,
m_cost(GPOPT_INVALID_COST),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -184,7 +184,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop,
m_cost(GPOPT_INVALID_COST),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -226,7 +226,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop,
m_cost(GPOPT_INVALID_COST),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -260,7 +260,7 @@ CExpression::CExpression(CMemoryPool *mp, COperator *pop,
m_cost(cost),
m_ulOriginGrpId(gpos::ulong_max),
m_ulOriginGrpExprId(gpos::ulong_max),
m_motionInputSegments(NULL)
m_motionInputSegmentsNumber(0)
{
GPOS_ASSERT(NULL != mp);
GPOS_ASSERT(NULL != pop);
Expand Down Expand Up @@ -432,7 +432,7 @@ CExpression::AssertValidPropDerivation(const CDrvdProp::EPropType ept)
#endif // GPOS_DEBUG

void
CExpression::SetMotionInputsForChildren()
CExpression::SetMotionInputsNumberForChildren()
{
const ULONG arity = Arity();

Expand All @@ -446,7 +446,7 @@ CExpression::SetMotionInputsForChildren()
opid != COperator::EopPhysicalMotionHashDistribute &&
opid != COperator::EopPhysicalMotionRoutedDistribute &&
opid != COperator::EopPhysicalMotionRandom)
pexprChild->SetMotionInputs(m_motionInputSegments);
pexprChild->SetMotionInputsNumber(m_motionInputSegmentsNumber);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/backend/gporca/libgpopt/src/optimizer/COptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ COptimizer::PdxlnOptimize(
CExpression *pexprPlan = PexprOptimize(mp, pqc, search_stage_array);
GPOS_CHECK_ABORT;

pexprPlan->SetMotionInputs(NULL);

// translate plan into DXL
pdxlnPlan = CreateDXLNode(mp, md_accessor, pexprPlan,
pqc->PdrgPcr(), pdrgpmdname, ulHosts);
Expand Down
20 changes: 13 additions & 7 deletions src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,14 @@ CTranslatorExprToDXL::CreateDXLNode(CExpression *pexpr,
COperator::EopPhysicalMotionRandom == ulOpId)
{
gpos::IntPtrArray *inputSegmentInfo = GetInputSegIdsArray(pexpr);
pexpr->SetMotionInputs(inputSegmentInfo);

if (NULL != inputSegmentInfo)
{
pexpr->SetMotionInputsNumber(inputSegmentInfo->Size());
CRefCount::SafeRelease(inputSegmentInfo);
}
else
pexpr->SetMotionInputsNumber(0);
}
PfPdxlnPhysical pf = m_rgpfPhysicalTranslators[ulOpId];
if (NULL == pf)
Expand All @@ -470,7 +477,7 @@ CTranslatorExprToDXL::CreateDXLNode(CExpression *pexpr,
// are no longer needed
CDXLNode *pdxlnNew = NULL;

pexpr->SetMotionInputsForChildren();
pexpr->SetMotionInputsNumberForChildren();

CDXLNode *dxlnode = (this->*pf)(pexpr, colref_array, pdrgpdsBaseTables,
pulNonGatherMotions, pfDML);
Expand Down Expand Up @@ -4440,8 +4447,6 @@ CTranslatorExprToDXL::PdxlnMotion(CExpression *pexprMotion,
GPOS_ASSERT(NULL != pexprMotion);
GPOS_ASSERT(1 == pexprMotion->Arity());

gpos::IntPtrArray *inputSegmentInfo = GetInputSegIdsArray(pexprMotion);

// extract components
CExpression *pexprChild = (*pexprMotion)[0];

Expand Down Expand Up @@ -4531,7 +4536,8 @@ CTranslatorExprToDXL::PdxlnMotion(CExpression *pexprMotion,
m_mp, m_pcf, m_phmcrdxln, pdxlnProjListChild);

// set input and output segment information
motion->SetSegmentInfo(inputSegmentInfo, GetOutputSegIdsArray(pexprMotion));
motion->SetSegmentInfo(GetInputSegIdsArray(pexprMotion),
GetOutputSegIdsArray(pexprMotion));

CDXLNode *pdxlnMotion = GPOS_NEW(m_mp) CDXLNode(m_mp, motion);
CDXLPhysicalProperties *dxl_properties = GetProperties(pexprMotion);
Expand Down Expand Up @@ -7652,8 +7658,8 @@ CTranslatorExprToDXL::GetProperties(const CExpression *pexpr)
{
// if distribution is replicated, multiply number of rows by number of segments
ULONG ulSegments =
pexpr->GetMotionInputs()
? pexpr->GetMotionInputs()->Size()
pexpr->GetMotionInputsNumber() > 0
? pexpr->GetMotionInputsNumber()
: COptCtxt::PoctxtFromTLS()->GetCostModel()->UlHosts();
rows = rows * ulSegments;
}
Expand Down

0 comments on commit cd341ba

Please sign in to comment.