This is an automated email from the ASF dual-hosted git repository.
maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push:
new 793971e8dd4 ORCA: use backtrace replace the foreach nested foreach
793971e8dd4 is described below
commit 793971e8dd4c833838bb1656b2e538d1c4078d08
Author: zhoujiaqi <[email protected]>
AuthorDate: Mon Jul 7 17:40:23 2025 +0800
ORCA: use backtrace replace the foreach nested foreach
---
.../libgpopt/include/gpopt/operators/CPhysical.h | 5 ++
.../gporca/libgpopt/src/operators/CPhysical.cpp | 63 ++++++++++++----------
2 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/src/backend/gporca/libgpopt/include/gpopt/operators/CPhysical.h
b/src/backend/gporca/libgpopt/include/gpopt/operators/CPhysical.h
index 84b1b0f8ac9..9924a3293fd 100644
--- a/src/backend/gporca/libgpopt/include/gpopt/operators/CPhysical.h
+++ b/src/backend/gporca/libgpopt/include/gpopt/operators/CPhysical.h
@@ -158,6 +158,11 @@ private:
// total number of optimization requests
ULONG m_ulTotalOptRequests;
+ // use back trace generate the opt requires
+ void BackTraceOptRequests(UlongPtrArray *pdrgpulpOptReqsExpanded,
+ const ULONG
*ulOptReqs, ULONG ulOptReqsSize,
+ ULONG_PTR *current,
ULONG cursz);
+
// update number of requests of a given property
void UpdateOptRequests(ULONG ulPropIndex, ULONG ulRequests);
diff --git a/src/backend/gporca/libgpopt/src/operators/CPhysical.cpp
b/src/backend/gporca/libgpopt/src/operators/CPhysical.cpp
index 3f17280221c..bbc1650a357 100644
--- a/src/backend/gporca/libgpopt/src/operators/CPhysical.cpp
+++ b/src/backend/gporca/libgpopt/src/operators/CPhysical.cpp
@@ -59,6 +59,35 @@ CPhysical::CPhysical(CMemoryPool *mp)
}
+//---------------------------------------------------------------------------
+// @function:
+// CPhysical::BackTraceOptRequests
+//
+// @doc:
+// Use back trace to generated the
+//
+//---------------------------------------------------------------------------
+void
+CPhysical::BackTraceOptRequests(UlongPtrArray *pdrgpulpOptReqsExpanded,
+ const ULONG
*ulOptReqs, ULONG ulOptReqsSize,
+ ULONG_PTR
*current, ULONG cursz)
+{
+ if (cursz == ulOptReqsSize)
+ {
+ ULONG_PTR *copyOne = GPOS_NEW_ARRAY(m_mp, ULONG_PTR,
GPOPT_PLAN_PROPS);
+ clib::Memcpy(copyOne, current, GPOPT_PLAN_PROPS *
sizeof(ULONG_PTR));
+ pdrgpulpOptReqsExpanded->Append(copyOne);
+ return;
+ }
+
+ for (ULONG i = 0; i < ulOptReqs[cursz]; i++)
+ {
+ current[cursz] = i;
+ BackTraceOptRequests(pdrgpulpOptReqsExpanded, ulOptReqs,
ulOptReqsSize,
+ current, cursz + 1);
+ }
+}
+
//---------------------------------------------------------------------------
// @function:
// CPhysical::UpdateOptRequests
@@ -88,37 +117,17 @@ CPhysical::UpdateOptRequests(ULONG ulPropIndex, ULONG
ulRequests)
m_ulTotalOptRequests = ulOptReqs;
// update expanded requests
- const ULONG ulOrderRequests = UlOrderRequests();
- const ULONG ulDistrRequests = UlDistrRequests();
- const ULONG ulRewindRequests = UlRewindRequests();
- const ULONG ulPartPropagateRequests = UlPartPropagateRequests();
+ ULONG ulaOptReqs[GPOPT_PLAN_PROPS] = {UlOrderRequests(),
UlDistrRequests(),
+
UlRewindRequests(),
+
UlPartPropagateRequests()};
CRefCount::SafeRelease(m_pdrgpulpOptReqsExpanded);
- m_pdrgpulpOptReqsExpanded = nullptr;
m_pdrgpulpOptReqsExpanded = GPOS_NEW(m_mp) UlongPtrArray(m_mp);
- for (ULONG ulOrder = 0; ulOrder < ulOrderRequests; ulOrder++)
- {
- for (ULONG ulDistr = 0; ulDistr < ulDistrRequests; ulDistr++)
- {
- for (ULONG ulRewind = 0; ulRewind < ulRewindRequests;
ulRewind++)
- {
- for (ULONG ulPartPropagate = 0;
- ulPartPropagate <
ulPartPropagateRequests;
- ulPartPropagate++)
- {
- ULONG_PTR *pulpRequest =
- GPOS_NEW_ARRAY(m_mp, ULONG_PTR,
GPOPT_PLAN_PROPS);
-
- pulpRequest[0] = ulOrder;
- pulpRequest[1] = ulDistr;
- pulpRequest[2] = ulRewind;
- pulpRequest[3] = ulPartPropagate;
-
m_pdrgpulpOptReqsExpanded->Append(pulpRequest);
- }
- }
- }
- }
+ ULONG_PTR *pulpRequest = GPOS_NEW_ARRAY(m_mp, ULONG_PTR,
GPOPT_PLAN_PROPS);
+ BackTraceOptRequests(m_pdrgpulpOptReqsExpanded, ulaOptReqs,
+ GPOPT_PLAN_PROPS, pulpRequest,
0);
+ GPOS_DELETE_ARRAY(pulpRequest);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]