59 lines
1.4 KiB
SQL
59 lines
1.4 KiB
SQL
# name: test/optimizer/pushdown/issue_18653.test
|
|
# description: Performance issue with CROSS JOIN and LATERAL JOIN combined with unnest and json_each. Filter should be pushed down to reduce the joined rows
|
|
# group: [pushdown]
|
|
|
|
statement ok
|
|
PRAGMA enable_verification
|
|
|
|
statement ok
|
|
create table test_table as
|
|
select s.i as id, [1, 2, 3]::bigint[] as values from generate_series(1, 1000000) as s(i);
|
|
|
|
statement ok
|
|
create index test_table_id_idx on test_table(id);
|
|
|
|
query II
|
|
explain analyze
|
|
select id, value
|
|
from test_table
|
|
cross join unnest(values) as values(value) where id = 87100;
|
|
----
|
|
analyzed_plan <REGEX>:.*LEFT_DELIM_JOIN.*FILTER.*
|
|
|
|
query II
|
|
select id, value
|
|
from test_table
|
|
cross join unnest(values) as values(value) where id = 87100;
|
|
----
|
|
87100 3
|
|
87100 2
|
|
87100 1
|
|
|
|
query II
|
|
explain analyze
|
|
select id, value
|
|
from test_table t
|
|
left join lateral unnest(t.values) as value on true
|
|
where id = 87100;
|
|
----
|
|
analyzed_plan <REGEX>:.*LEFT_DELIM_JOIN.*FILTER.*
|
|
|
|
require json
|
|
|
|
statement ok
|
|
create table test_table2 as
|
|
select s.i as id, '{"key1": 1, "key2": 2, "key3": 3}'::JSON as values
|
|
from generate_series(1, 1000000) as s(i);
|
|
|
|
statement ok
|
|
create index test_table2_id_idx on test_table2(id);
|
|
|
|
query II
|
|
explain analyze
|
|
select t.id, key, value
|
|
from test_table2 t
|
|
cross join json_each(t.values) as kv(key, value)
|
|
where t.id = 87100;
|
|
----
|
|
analyzed_plan <REGEX>:.*LEFT_DELIM_JOIN.*Filters:.*id=87100.*
|