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

commit 6c289ada596aa16e9bfb7284e535530102cf79a9
Author: zhoujiaqi <[email protected]>
AuthorDate: Wed Dec 25 18:14:33 2024 +0800

    FIX: Ordered set agg with a ref type column will generate coredump
    
    GPDB have the same issue. The current issue was introduced by
    "Update ordered-set agg preprocess step for skew"(GPDP commit 5280297)
    
    This is because a not null DATUM(0) is returned during the call
    function to gp_percentile_disc_transition.
---
 .../gporca/libgpopt/src/operators/COrderedAggPreprocessor.cpp        | 2 +-
 src/backend/utils/adt/orderedsetaggs.c                               | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/src/backend/gporca/libgpopt/src/operators/COrderedAggPreprocessor.cpp 
b/src/backend/gporca/libgpopt/src/operators/COrderedAggPreprocessor.cpp
index f135944cdf..03e3200d5d 100644
--- a/src/backend/gporca/libgpopt/src/operators/COrderedAggPreprocessor.cpp
+++ b/src/backend/gporca/libgpopt/src/operators/COrderedAggPreprocessor.cpp
@@ -289,7 +289,7 @@ COrderedAggPreprocessor::SplitPrjList(
                        // Is it necessary to keep `m_func_format` in 
`CScalarFunc`?
                        CScalarFunc *popCastScalarFunc = GPOS_NEW(mp) 
CScalarFunc(
                                mp, mdid_func, cast_func->GetResultTypeMdid(), 
-1, pstrFunc, 
-                               1);
+                               1 /* Explicit Cast */);
                        CExpression *pexprCastScalarIdent = GPOS_NEW(mp)
                                CExpression(mp, popCastScalarFunc, 
pexprScalarIdentSum);
                        CExpressionArray *colref_array1 = GPOS_NEW(mp) 
CExpressionArray(mp);
diff --git a/src/backend/utils/adt/orderedsetaggs.c 
b/src/backend/utils/adt/orderedsetaggs.c
index a2eb8a8e12..46b2694d89 100644
--- a/src/backend/utils/adt/orderedsetaggs.c
+++ b/src/backend/utils/adt/orderedsetaggs.c
@@ -1634,6 +1634,7 @@ gp_percentile_disc_transition(PG_FUNCTION_ARGS)
                                 errmsg("percentile value %g is not between 0 
and 1",
                                                percentile)));
        Datum prev_state = PG_GETARG_DATUM(0);
+       bool prev_state_isnull = PG_ARGISNULL(0);
        Datum val = PG_GETARG_DATUM(1);
        Datum return_state = prev_state;
        int64 total_rows = PG_GETARG_INT64(3);
@@ -1668,6 +1669,10 @@ gp_percentile_disc_transition(PG_FUNCTION_ARGS)
                fcinfo->flinfo->fn_extra = NULL;
        }
 
+       if (return_state == prev_state) {
+               fcinfo->isnull = prev_state_isnull;
+       }
+
        PG_RETURN_DATUM(return_state);
 }
 


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

Reply via email to