Skip to content

Commit 1981e63

Browse files
jiaqizhotuhaihe
authored andcommitted
ORCA: use backtrace replace the foreach nested foreach
1 parent a7659f6 commit 1981e63

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

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

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

161+
// use back trace generate the opt requires
162+
void BackTraceOptRequests(UlongPtrArray *pdrgpulpOptReqsExpanded,
163+
const ULONG *ulOptReqs, ULONG ulOptReqsSize,
164+
ULONG_PTR *current, ULONG cursz);
165+
161166
// update number of requests of a given property
162167
void UpdateOptRequests(ULONG ulPropIndex, ULONG ulRequests);
163168

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

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ CPhysical::CPhysical(CMemoryPool *mp)
5959
}
6060

6161

62+
//---------------------------------------------------------------------------
63+
// @function:
64+
// CPhysical::BackTraceOptRequests
65+
//
66+
// @doc:
67+
// Use back trace to generated the
68+
//
69+
//---------------------------------------------------------------------------
70+
void
71+
CPhysical::BackTraceOptRequests(UlongPtrArray *pdrgpulpOptReqsExpanded,
72+
const ULONG *ulOptReqs, ULONG ulOptReqsSize,
73+
ULONG_PTR *current, ULONG cursz)
74+
{
75+
if (cursz == ulOptReqsSize)
76+
{
77+
ULONG_PTR *copyOne = GPOS_NEW_ARRAY(m_mp, ULONG_PTR, GPOPT_PLAN_PROPS);
78+
clib::Memcpy(copyOne, current, GPOPT_PLAN_PROPS * sizeof(ULONG_PTR));
79+
pdrgpulpOptReqsExpanded->Append(copyOne);
80+
return;
81+
}
82+
83+
for (ULONG i = 0; i < ulOptReqs[cursz]; i++)
84+
{
85+
current[cursz] = i;
86+
BackTraceOptRequests(pdrgpulpOptReqsExpanded, ulOptReqs, ulOptReqsSize,
87+
current, cursz + 1);
88+
}
89+
}
90+
6291
//---------------------------------------------------------------------------
6392
// @function:
6493
// CPhysical::UpdateOptRequests
@@ -88,37 +117,17 @@ CPhysical::UpdateOptRequests(ULONG ulPropIndex, ULONG ulRequests)
88117
m_ulTotalOptRequests = ulOptReqs;
89118

90119
// update expanded requests
91-
const ULONG ulOrderRequests = UlOrderRequests();
92-
const ULONG ulDistrRequests = UlDistrRequests();
93-
const ULONG ulRewindRequests = UlRewindRequests();
94-
const ULONG ulPartPropagateRequests = UlPartPropagateRequests();
120+
ULONG ulaOptReqs[GPOPT_PLAN_PROPS] = {UlOrderRequests(), UlDistrRequests(),
121+
UlRewindRequests(),
122+
UlPartPropagateRequests()};
95123

96124
CRefCount::SafeRelease(m_pdrgpulpOptReqsExpanded);
97-
m_pdrgpulpOptReqsExpanded = nullptr;
98125
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);
111-
112-
pulpRequest[0] = ulOrder;
113-
pulpRequest[1] = ulDistr;
114-
pulpRequest[2] = ulRewind;
115-
pulpRequest[3] = ulPartPropagate;
116126

117-
m_pdrgpulpOptReqsExpanded->Append(pulpRequest);
118-
}
119-
}
120-
}
121-
}
127+
ULONG_PTR *pulpRequest = GPOS_NEW_ARRAY(m_mp, ULONG_PTR, GPOPT_PLAN_PROPS);
128+
BackTraceOptRequests(m_pdrgpulpOptReqsExpanded, ulaOptReqs,
129+
GPOPT_PLAN_PROPS, pulpRequest, 0);
130+
GPOS_DELETE_ARRAY(pulpRequest);
122131
}
123132

124133

0 commit comments

Comments
 (0)