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 05e3a73e706b1b9ef5a79871dc1a2d4cd10d78aa
Author: Zhenghua Lyu <[email protected]>
AuthorDate: Wed Mar 30 15:06:35 2022 +0800

    Fix test case notin.
    
    Commit fe44b1f7a use negate_clause instead of make_notclause,
    this might lead to (NOT =) become <>, semantically they should
    be the same. But in later convert_IN_to_antijoin, it does not
    consider sublink expr is OpExpr thus fails a test case notin,
    results in plan change.
    
    A case is shown below (regress/notin q43):
    
      explain select c1 from t1
      where c1 not in (select c2 from t2 where c2 > 4)
        and c1 is not null;
    
    This commit fixes the failure case by considering OpExpr in
    convert_IN_to_antijoin.
---
 src/backend/cdb/cdbsubselect.c            | 2 ++
 src/backend/optimizer/prep/prepjointree.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/backend/cdb/cdbsubselect.c b/src/backend/cdb/cdbsubselect.c
index 2a7fef99b2..07fd8d0f6a 100644
--- a/src/backend/cdb/cdbsubselect.c
+++ b/src/backend/cdb/cdbsubselect.c
@@ -1351,6 +1351,8 @@ fetch_outer_exprs(Node *testexpr)
                else
                        return NIL;
        }
+       else if (IsA(testexpr, OpExpr))
+               return list_make1(linitial(((OpExpr *)testexpr)->args));
        else
                return NIL;
 }
diff --git a/src/backend/optimizer/prep/prepjointree.c 
b/src/backend/optimizer/prep/prepjointree.c
index b4ed3c570d..86b7fb2a7a 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -676,7 +676,7 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node,
                        else if (sublink->subLinkType == ANY_SUBLINK || 
sublink->subLinkType == ALL_SUBLINK)
                        {
                                sublink->subLinkType = (sublink->subLinkType == 
ANY_SUBLINK) ? ALL_SUBLINK : ANY_SUBLINK;
-                               sublink->testexpr = (Node *) 
canonicalize_qual((Expr*)negate_clause(sublink->testexpr), false);
+                               sublink->testexpr = (Node *) 
canonicalize_qual((Expr *) negate_clause(sublink->testexpr), false);
                                return pull_up_sublinks_qual_recurse(root, 
(Node *) sublink,
                                                                                
                                jtlink1, available_rels1,
                                                                                
                                jtlink2, available_rels2);


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

Reply via email to