Skip to content

Commit e4150e1

Browse files
committed
ORCA: use backtrace replace the foreach nested foreach
1 parent ffce584 commit e4150e1

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/backend/gporca/libgpopt/include/gpopt/operators/CPhysical.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ class CPhysical : public COperator
158158
// total number of optimization requests
159159
ULONG m_ulTotalOptRequests;
160160

161+
void BackTraceOptRequests(const ULONG *ulOptReqs, ULONG ulOptReqsSize,
162+
UlongPtrArray *pdrgpulpOptReqsExpanded, ULONG_PTR *current, ULONG cursz);
163+
161164
// update number of requests of a given property
162165
void UpdateOptRequests(ULONG ulPropIndex, ULONG ulRequests);
163166

src/backend/gporca/libgpopt/src/operators/CPhysical.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ CPhysical::CPhysical(CMemoryPool *mp)
5858
m_phmrcr = GPOS_NEW(mp) ReqdColsReqToColRefSetMap(mp);
5959
}
6060

61+
void
62+
CPhysical::BackTraceOptRequests(const ULONG *ulOptReqs, ULONG ulOptReqsSize,
63+
UlongPtrArray *pdrgpulpOptReqsExpanded, ULONG_PTR *current, ULONG cursz) {
64+
if (cursz == ulOptReqsSize) {
65+
ULONG_PTR *copyOne = GPOS_NEW_ARRAY(m_mp, ULONG_PTR, GPOPT_PLAN_PROPS);
66+
clib::Memcpy(copyOne, current, GPOPT_PLAN_PROPS * sizeof(ULONG));
67+
pdrgpulpOptReqsExpanded->Append(copyOne);
68+
return;
69+
}
70+
71+
for (ULONG i = 0; i < ulOptReqs[cursz]; i++) {
72+
current[cursz++] = i;
73+
BackTraceOptRequests(ulOptReqs, ulOptReqsSize, pdrgpulpOptReqsExpanded, current, cursz);
74+
cursz--;
75+
}
76+
}
6177

6278
//---------------------------------------------------------------------------
6379
// @function:
@@ -88,37 +104,17 @@ CPhysical::UpdateOptRequests(ULONG ulPropIndex, ULONG ulRequests)
88104
m_ulTotalOptRequests = ulOptReqs;
89105

90106
// update expanded requests
91-
const ULONG ulOrderRequests = UlOrderRequests();
92-
const ULONG ulDistrRequests = UlDistrRequests();
93-
const ULONG ulRewindRequests = UlRewindRequests();
94-
const ULONG ulPartPropagateRequests = UlPartPropagateRequests();
107+
ULONG ulaOptReqs[GPOPT_PLAN_PROPS] = {
108+
UlOrderRequests(), UlDistrRequests(),
109+
UlRewindRequests(), UlPartPropagateRequests()
110+
};
95111

96112
CRefCount::SafeRelease(m_pdrgpulpOptReqsExpanded);
97-
m_pdrgpulpOptReqsExpanded = nullptr;
98113
m_pdrgpulpOptReqsExpanded = GPOS_NEW(m_mp) UlongPtrArray(m_mp);
99-
for (ULONG ulOrder = 0; ulOrder < ulOrderRequests; ulOrder++)
100-
{
101-
for (ULONG ulDistr = 0; ulDistr < ulDistrRequests; ulDistr++)
102-
{
103-
for (ULONG ulRewind = 0; ulRewind < ulRewindRequests; ulRewind++)
104-
{
105-
for (ULONG ulPartPropagate = 0;
106-
ulPartPropagate < ulPartPropagateRequests;
107-
ulPartPropagate++)
108-
{
109-
ULONG_PTR *pulpRequest =
110-
GPOS_NEW_ARRAY(m_mp, ULONG_PTR, GPOPT_PLAN_PROPS);
111114

112-
pulpRequest[0] = ulOrder;
113-
pulpRequest[1] = ulDistr;
114-
pulpRequest[2] = ulRewind;
115-
pulpRequest[3] = ulPartPropagate;
116-
117-
m_pdrgpulpOptReqsExpanded->Append(pulpRequest);
118-
}
119-
}
120-
}
121-
}
115+
ULONG_PTR *pulpRequest = GPOS_NEW_ARRAY(m_mp, ULONG_PTR, GPOPT_PLAN_PROPS);
116+
BackTraceOptRequests(ulaOptReqs, GPOPT_PLAN_PROPS, m_pdrgpulpOptReqsExpanded, pulpRequest, 0);
117+
GPOS_DELETE_ARRAY(pulpRequest);
122118
}
123119

124120

0 commit comments

Comments
 (0)