leborchuk commented on code in PR #1192:
URL: https://github.com/apache/cloudberry/pull/1192#discussion_r2259445963


##########
src/backend/gporca/libgpopt/src/operators/CPhysicalAgg.cpp:
##########
@@ -293,11 +292,65 @@ CDistributionSpec *
 CPhysicalAgg::PdsMaximalHashed(CMemoryPool *mp, CColRefArray *colref_array)
 {
        GPOS_ASSERT(nullptr != colref_array);
+       CColRefArray *pcraResHashs = nullptr;
+
+       if (GPOS_FTRACE(EopttraceAggRRSFirstKey)) {
+               pcraResHashs = GPOS_NEW(mp) CColRefArray(mp);
+               if (colref_array->Size() > 0) {
+                       CColRef *colref = (*colref_array)[0];
+                       pcraResHashs->Append(colref);
+               }
+       } else if (GPOS_FTRACE(EopttraceAggRRSMinimalLenKey)) {
+               ULONG ulsz = colref_array->Size();
+               pcraResHashs = GPOS_NEW(mp) CColRefArray(mp);
+
+               LINT minimal_typlen = gpos::lint_max; // less than minimal 
typlen
+               LINT minimal_typlen_ul = -1;
+               for (ULONG ul = 0; ul < ulsz; ul++) {
+                       CColRef *pcr =(*colref_array)[ul];
+                       const gpmd::IMDType *pmdtyp = pcr->RetrieveType();
+                       LINT typlen = pmdtyp->IsFixedLength() ? 
pmdtyp->Length() : (gpos::lint_max - 1);
+
+                       if (typlen < minimal_typlen) {
+                               minimal_typlen = typlen;
+                               minimal_typlen_ul = ul;
+                       }
+               }
+
+               if (minimal_typlen_ul != -1) {

Review Comment:
   Hmmm, what if we do not check for minimal_typlen_ul != -1  here because it's 
impossible. And if  minimal_typlen_ul == -1 we will catch assert on line 346 
but will not know why the pcraResHashs->Size()  is zero. Instead we could write 
GPOS_ASSERT(minimal_typlen_ul != -1);



##########
src/backend/gporca/libgpopt/src/operators/CPhysicalAgg.cpp:
##########
@@ -293,11 +292,65 @@ CDistributionSpec *
 CPhysicalAgg::PdsMaximalHashed(CMemoryPool *mp, CColRefArray *colref_array)
 {
        GPOS_ASSERT(nullptr != colref_array);
+       CColRefArray *pcraResHashs = nullptr;
+
+       if (GPOS_FTRACE(EopttraceAggRRSFirstKey)) {
+               pcraResHashs = GPOS_NEW(mp) CColRefArray(mp);
+               if (colref_array->Size() > 0) {

Review Comment:
   Here we could get the empty pcraResHashs if colref_array size is 0. Maybe 
check `GPOS_ASSERT_IMP(colref_array->Size() > 0);` at the beginning and not to 
check anymore?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to