Re: UNION versus SUB SELECT
От | desmodemone |
---|---|
Тема | Re: UNION versus SUB SELECT |
Дата | |
Msg-id | CAEs9oFmh_HWbC_JZ9Ng1G8hXm4YrfPrNM+51M+F0h6pTMo-E5A@mail.gmail.com обсуждение исходный текст |
Ответ на | UNION versus SUB SELECT (Robert DiFalco <robert.difalco@gmail.com>) |
Ответы |
Re: UNION versus SUB SELECT
Re: UNION versus SUB SELECT |
Список | pgsql-performance |
Hi Robert, could you try with "exists" ?
2013/11/21 Robert DiFalco <robert.difalco@gmail.com>
I have found this:SELECT c.*FROM contacts cWHERE c.id IN ( SELECT p.contact_id FROM phone p WHERE p.addr = ? )OR c.id IN (SELECT e.contact_id FROM email e WHERE e.addr = ? );To have a worse plan than:SELECT * FROM contacts where id IN (( SELECT c.id FROM contacts cJOIN phone p ON c.id = p.contact_id AND p.addr = ?UNIONSELECT c.id FROM contacts cJOIN email e ON c.id = e.contact_id AND e.addr = ? );Maybe this is no surprise. But after discovering this my question is this, is there another option I dont' know about that is logically the same that can perform even better than the UNION?
В списке pgsql-performance по дате отправления: