diff --git a/src/postgres/src/backend/optimizer/path/indxpath.c b/src/postgres/src/backend/optimizer/path/indxpath.c index 0fbc055eb6f8..c871222f3223 100644 --- a/src/postgres/src/backend/optimizer/path/indxpath.c +++ b/src/postgres/src/backend/optimizer/path/indxpath.c @@ -718,7 +718,7 @@ yb_get_batched_index_paths(PlannerInfo *root, RelOptInfo *rel, yb_get_batched_restrictinfo(rinfo, batchedrelids, index->rel->relids); - if (!bms_is_subset(batched_and_inner_relids, rinfo->clause_relids)) + if (!bms_overlap(rinfo->clause_relids, batchedrelids)) continue; Assert(bms_overlap(rinfo->clause_relids, batchedrelids)); diff --git a/src/postgres/src/test/regress/expected/yb_join_batching.out b/src/postgres/src/test/regress/expected/yb_join_batching.out index fc64d45abda2..675408ceb7ed 100644 --- a/src/postgres/src/test/regress/expected/yb_join_batching.out +++ b/src/postgres/src/test/regress/expected/yb_join_batching.out @@ -1829,6 +1829,31 @@ a = int4table.a; drop table oidtable; drop table int4table; +create table ss1(a int); +create table ss2(a int); +create table ss3(a int, b int, primary key(a asc, b asc)); +-- Should not result in an illegal BNL on the inner side +/*+Leading((ss1 (ss2 ss3)))*/ explain (costs off) select * from ss1, ss2, ss3 where ss3.a = ss2.a and ss3.b = ss1.a and ss3.a <> ss2.a; + QUERY PLAN +------------------------------------------------------------------------------ + YB Batched Nested Loop Join + Join Filter: (ss3.b = ss1.a) + -> Seq Scan on ss1 + -> Nested Loop + -> Seq Scan on ss2 + -> Index Scan using ss3_pkey on ss3 + Index Cond: ((b = ANY (ARRAY[ss1.a, $1, $2])) AND (a = ss2.a)) + Filter: (a <> ss2.a) +(8 rows) + +/*+Leading((ss1 (ss2 ss3)))*/ select * from ss1, ss2, ss3 where ss3.a = ss2.a and ss3.b = ss1.a and ss3.a <> ss2.a; + a | a | a | b +---+---+---+--- +(0 rows) + +drop table ss1; +drop table ss2; +drop table ss3; SELECT '' AS "xxx", * FROM J1_TBL AS tx order by 1, 2, 3, 4; xxx | i | j | t diff --git a/src/postgres/src/test/regress/sql/yb_join_batching.sql b/src/postgres/src/test/regress/sql/yb_join_batching.sql index 5c44f85f9ba6..94fd6db2ca23 100644 --- a/src/postgres/src/test/regress/sql/yb_join_batching.sql +++ b/src/postgres/src/test/regress/sql/yb_join_batching.sql @@ -515,6 +515,17 @@ a = int4table.a; drop table oidtable; drop table int4table; +create table ss1(a int); +create table ss2(a int); +create table ss3(a int, b int, primary key(a asc, b asc)); + +-- Should not result in an illegal BNL on the inner side +/*+Leading((ss1 (ss2 ss3)))*/ explain (costs off) select * from ss1, ss2, ss3 where ss3.a = ss2.a and ss3.b = ss1.a and ss3.a <> ss2.a; +/*+Leading((ss1 (ss2 ss3)))*/ select * from ss1, ss2, ss3 where ss3.a = ss2.a and ss3.b = ss1.a and ss3.a <> ss2.a; +drop table ss1; +drop table ss2; +drop table ss3; + SELECT '' AS "xxx", * FROM J1_TBL AS tx order by 1, 2, 3, 4;