I have this statement:
select qulified_name
from table
inner join references_table on references_table.id = table.ref_id
where references_table.type = 'x' and table.value in (... +110 000 ids)
which is extremly slow. (The web app crashes and doesn't get a result. I create my statement with the help of rom-rb and this uses sequel. But this is the statement I get when I take a look at the statement.
If I rewrite the satement like this the performance is really good compared to the first version:
select qulified_name
from table
inner join (select unnest(array['#{references_id.join("','")}']) id ) as tmp on tmp.id = businesspartner_references.value
inner join references_table on references_table.id = table.ref_id
where references_table.type = 'x'
This way I get the result in ~3 sec.
Can someone explain to me why this is the case? I don't understand it..