Skip to content

Commit

Permalink
[#21292] YSQL: Fix logic to detect unbatchable filters
Browse files Browse the repository at this point in the history
Summary:
This change fixes a bug where we would not detect some unbatchable filters when forming an indexpath if the indexpath acceptable batched values from more than one relation.

Needs backports to 2.20 and 2.18
Jira: DB-10208

Test Plan: ./yb_buid.sh --java-test "org.yb.pgsql.TestPgRegressJoin'

Reviewers: mtakahara

Reviewed By: mtakahara

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D33179
  • Loading branch information
tanujnay112 committed Mar 15, 2024
1 parent cc6c220 commit ad87ceb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/postgres/src/backend/optimizer/path/indxpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions src/postgres/src/test/regress/expected/yb_join_batching.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/postgres/src/test/regress/sql/yb_join_batching.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit ad87ceb

Please sign in to comment.