I have tables
dn_table ~ 10_000 rows
| DN |
--------
| 1234 |
| 1235 |
| .... |
sr_table ~ 1m rows
| SR |
--------
| 2345 |
| 2346 |
| .... |
And I stuck with a lateral join query for them. It has extremely bad performance some queries are running for hours depending on dataset size while selecting with the limit.
select
*
from (
select
"alias1"."DN",
"alias2"."SR"
from (
select "alias1"."DN"
from "dn_table" as "alias1"
) as "alias1" left outer join lateral (
select *
from "sr_table" as "alias2"
where "alias1"."DN" = "alias2"."SR"
limit 1
) as "alias2" on true
) as "alias"
I've tried to use correlated subquery for them but it brings me results that I don't expect.
Thanks in advance!