Waloid24 commented on PR #2067:
URL: https://github.com/apache/cloudberry/pull/2067#issuecomment-5917388183

   It literally does the same as 
`CScaleFactorUtils::CalcScaleFactorCumulativeConj` here:
   ```
   void
   CScaleFactorUtils::SortScalingFactor(CDoubleArray *scale_factors,
                                                                         BOOL 
is_descending)
   {
        GPOS_ASSERT(nullptr != scale_factors);
        const ULONG num_cols = scale_factors->Size();
        if (1 < num_cols)
        {
                if (is_descending)
                {
                        // sort (in desc order) the scaling factor based on the 
selectivity of each column
                        
scale_factors->Sort(CScaleFactorUtils::DescendingOrderCmpFunc);
                }
                else
                {
                        // sort (in ascending order) the scaling factor based 
on the selectivity of each column
                        
scale_factors->Sort(CScaleFactorUtils::AscendingOrderCmpFunc);
                }
        }
   }
   ```
   We have descending order, so we will do the same action: 
`scale_factors->Sort(CScaleFactorUtils::DescendingOrderCmpFunc);` as 
`CScaleFactorUtils::CalcScaleFactorCumulativeConj` (see below) does:
   - `if (1 < num_cols)` then we sort it in the descending order: 
`scale_factors->Sort(CScaleFactorUtils::DescendingOrderCmpFunc);`
   - otherwise doesn't sort at all
   
   
   ```
   CDouble
   CScaleFactorUtils::CalcScaleFactorCumulativeConj(
        const CStatisticsConfig *stats_config, CDoubleArray *scale_factors)
   {
        GPOS_ASSERT(nullptr != stats_config);
        GPOS_ASSERT(nullptr != scale_factors);
   
        const ULONG num_cols = scale_factors->Size();
        CDouble scale_factor(1.0);
        if (1 < num_cols)
        {
                // sort (in desc order) the scaling factor based on the 
selectivity of each column
                scale_factors->Sort(CScaleFactorUtils::DescendingOrderCmpFunc);
        }
   
        for (ULONG ul = 0; ul < num_cols; ul++)
        {
                // apply damping factor
                CDouble local_scale_factor = *(*scale_factors)[ul];
                scale_factor =
                        scale_factor * std::max(CStatistics::MinRows.Get(),
                                                                        
(local_scale_factor *
                                                                         
CScaleFactorUtils::DampedFilterScaleFactor(
                                                                                
 stats_config, ul + 1))
                                                                                
.Get());
        }
   
        return scale_factor;
   }
   ```


-- 
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