This is an automated email from the ASF dual-hosted git repository.

tuhaihe pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 4b6618f501cc1f187443fa6386cb873d8d8a6bf8
Author: liushengsong <[email protected]>
AuthorDate: Mon Jun 15 14:42:07 2026 +0800

    Fix MERGE16_FIXME: add UNSAFE_HAS_SUBPLAN flag for qual pushdown
    
    The subplan check in check_output_expressions was incorrectly using
    UNSAFE_NOTIN_PARTITIONBY_CLAUSE, which only prevents normal pushdown
    but still allows the qual to be pushed as a window run condition.
    Subplans in output expressions should completely block pushdown in
    Cloudberry's distributed execution model.
    
    Add a dedicated UNSAFE_HAS_SUBPLAN flag and include it in the fully
    unsafe set in qual_is_pushdown_safe, so quals referencing output
    columns containing subplans are never pushed down.
---
 src/backend/optimizer/path/allpaths.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/backend/optimizer/path/allpaths.c 
b/src/backend/optimizer/path/allpaths.c
index 76ce1e8fbea..6bb0f9a92a5 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -74,6 +74,7 @@ bool          gp_enable_sort_limit = false;
 #define UNSAFE_NOTIN_DISTINCTON_CLAUSE (1 << 2)
 #define UNSAFE_NOTIN_PARTITIONBY_CLAUSE        (1 << 3)
 #define UNSAFE_TYPE_MISMATCH                   (1 << 4)
+#define UNSAFE_HAS_SUBPLAN                             (1 << 5)
 
 /* results of subquery_is_pushdown_safe */
 typedef struct pushdown_safety_info
@@ -4714,11 +4715,10 @@ check_output_expressions(Query *subquery, 
pushdown_safety_info *safetyInfo)
                        continue;
                }
 
-               /* Refuse subplans */
+               /* Refuse subplans (Cloudberry-specific, see 
UNSAFE_HAS_SUBPLAN) */
                if (contain_subplans((Node *) tle->expr))
                {
-                       /*.MERGE16_FIXME: should we add a new unsafe type? */
-                       safetyInfo->unsafeFlags[tle->resno] |= 
UNSAFE_NOTIN_PARTITIONBY_CLAUSE;
+                       safetyInfo->unsafeFlags[tle->resno] |= 
UNSAFE_HAS_SUBPLAN;
                        continue;
                }
        }
@@ -4896,7 +4896,8 @@ qual_is_pushdown_safe(Query *subquery, Index rti, 
RestrictInfo *rinfo,
                {
                        if (safetyInfo->unsafeFlags[var->varattno] &
                                (UNSAFE_HAS_VOLATILE_FUNC | UNSAFE_HAS_SET_FUNC 
|
-                                UNSAFE_NOTIN_DISTINCTON_CLAUSE | 
UNSAFE_TYPE_MISMATCH))
+                                UNSAFE_NOTIN_DISTINCTON_CLAUSE | 
UNSAFE_TYPE_MISMATCH |
+                                UNSAFE_HAS_SUBPLAN))
                        {
                                safe = PUSHDOWN_UNSAFE;
                                break;


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

Reply via email to