Subject RE: [firebird-support] Firebird 2.5: Optimize of IN or EXISTS performance
Author Svein Erling Tysvær
>SELECT * FROM ARTICLE_CONTENTTREE_LINK WHERE ARTICLEID in
>(Select RELID FROM ARTICLE WHERE DEFINEID=112435)
>
>SELECT * FROM ARTICLE_CONTENTTREE_LINK
>WHERE EXISTS
> (Select RELID FROM ARTICLE WHERE DEFINEID=112435
>AND ARTICLE.RELID=ARTICLE_CONTENTTREE_LINK.ARTICLEID)

I don't think these two queries could easily use an index for both tables (I think it could be implemented since the subqueries aren't correlated, but I don't think accommodating for lazy development should be put high on any priority list - though note that I don't know whether it has been implemented or not).

Modify your query a bit, and it should use your indexes:

WITH ARTICLE2 AS
(SELECT DISTINCT RELID
FROM ARTICLE WHERE DEFINEID=112435)

SELECT A.*
FROM ARTICLE_CONTENTTREE_LINK A
JOIN ARTICLE2 A2 ON A.ARTICLEID=A2.RELID)

HTH,
Set