Open michae2 opened 4 months ago
Here's an opttest that shows the problem:
exec-ddl
CREATE TABLE abc (
a INT PRIMARY KEY,
b STRING,
c INT,
INDEX (b)
)
----
exec-ddl
CREATE TABLE cd (
c INT PRIMARY KEY,
d INT[]
)
----
optstepsweb
SELECT * FROM abc JOIN cd USING (c) WHERE b LIKE 'foo%' AND d @> ARRAY[123]
----
optstepsweb
SELECT * FROM abc JOIN cd USING (c) WHERE b LIKE 'foo%' AND 123 = ANY (SELECT unnest(d))
----
Looking at the optstepsweb output, I wonder if we should be less aggressive about pushing predicates below joins if those predicates contain subqueries? Maybe predicates containing subqueries should only be pushed down during exploration?
In the example below, we avoid a full scan of
cd
by using a lookup join intocd@primary
:But if we change the
d @> ARRAY[123]
predicate to use a correlated subquery over a set-generating function such as123 = ANY (SELECT unnest(d))
then it's no longer possible to plan a lookup join, and instead we get a full scan ofcd
:Jira issue: CRDB-40119