diff --git a/src/gausskernel/optimizer/plan/subselect.cpp b/src/gausskernel/optimizer/plan/subselect.cpp index 1ccba2b19..75756c6c1 100644 --- a/src/gausskernel/optimizer/plan/subselect.cpp +++ b/src/gausskernel/optimizer/plan/subselect.cpp @@ -6436,7 +6436,6 @@ void convert_ORCLAUSE_to_join(PlannerInfo *root, BoolExpr *or_clause, Node **jtl /* fall through */ case T_OpExpr: { - Node *notNullAnd = NULL; bool replace = false; ListCell *cell = NULL; @@ -6454,16 +6453,10 @@ void convert_ORCLAUSE_to_join(PlannerInfo *root, BoolExpr *or_clause, Node **jtl jtlink1, available_rels1, replace, isnull); if (notNullExpr != NULL) { - notNullAnd = make_and_qual(notNullAnd, notNullExpr); replace = true; } } - /* This opexpr's sublink always be pulled up, and it will be replaced with not null expr.*/ - - if (notNullAnd != NULL) { - or_clause = (BoolExpr*)replace_node_clause((Node*)or_clause, clause, notNullAnd, RNC_RECURSE_AGGREF); - } } break; diff --git a/src/test/regress/expected/sublink_pullup_enhance.out b/src/test/regress/expected/sublink_pullup_enhance.out index 007ee18d4..efdbe728e 100644 --- a/src/test/regress/expected/sublink_pullup_enhance.out +++ b/src/test/regress/expected/sublink_pullup_enhance.out @@ -883,3 +883,30 @@ order by -> Seq Scan on supplier (38 rows) +create table t1(c1 int,c2 int); +create table t2(c1 int,c2 int); +create table t3(c1 int,c2 int); +insert into t1 values(1,1),(2,2),(3,3); +insert into t2 values(1,1),(2,2),(3,3); +insert into t3 values(1,1),(2,2),(3,3); +select count(0) +from +( + select t1.* from t1 + where (( + (select count(1) + from t2 + where t2.c1=t1.c1) + + (select count(1) + from t3 + where t3.c1=t1.c1)) > 0 + or t1.c1 = 5) +) tmp_count; + count +------- + 3 +(1 row) + +drop table t1; +drop table t2; +drop table t3; diff --git a/src/test/regress/sql/sublink_pullup_enhance.sql b/src/test/regress/sql/sublink_pullup_enhance.sql index 11a72774f..f818bb2dc 100644 --- a/src/test/regress/sql/sublink_pullup_enhance.sql +++ b/src/test/regress/sql/sublink_pullup_enhance.sql @@ -343,3 +343,29 @@ order by n_name, s_name, p_partkey; + + +create table t1(c1 int,c2 int); +create table t2(c1 int,c2 int); +create table t3(c1 int,c2 int); +insert into t1 values(1,1),(2,2),(3,3); +insert into t2 values(1,1),(2,2),(3,3); +insert into t3 values(1,1),(2,2),(3,3); + +select count(0) +from +( + select t1.* from t1 + where (( + (select count(1) + from t2 + where t2.c1=t1.c1) + + (select count(1) + from t3 + where t3.c1=t1.c1)) > 0 + or t1.c1 = 5) +) tmp_count; + +drop table t1; +drop table t2; +drop table t3;