Re: [GENERAL] Trouble: subquery doesn't terminate
От | mwilson@the-wire.com (Mel Wilson) |
---|---|
Тема | Re: [GENERAL] Trouble: subquery doesn't terminate |
Дата | |
Msg-id | iuHk4ks/KjXZ089yn@the-wire.com обсуждение исходный текст |
Ответ на | Trouble: subquery doesn't terminate (mwilson@the-wire.com (Mel Wilson)) |
Список | pgsql-general |
In article <388EA1DD.6685C433@thinx.ch>, Herbert Liechti <Herbert.Liechti@thinx.ch> wrote: >> [ ... ] This query ran over 6 minutes >> before Apache timed out and dropped the pipe: >> >> $result = $conn->exec(qq/ >> SELECT t.tune_id, t.title >> FROM tune t >> WHERE t.tune_id IN >> (SELECT c.tune_id FROM composer c WHERE c.person_id = $person_id) >> /); >The IN Clause is known to be very slow. Try to use the EXISTS clause >instead. I had the same problem. After changing to the EXISTS >variant my performance troubles went away. Thanks for your reply. I'm not sure how to use EXISTS in this case (a list of tunes composed by a given person.) but it's a moot point since the fully joined query SELECT t.tune_id, t.title FROM tune t, composer c WHERE t.tune_id = c.tune_id AND $person_id = c.person_id ORDER BY t.title runs in 2 seconds. (in today's test .. while the sub-select was taking over 7:30 before Netscape killed it.) Thanks again. Mel.
В списке pgsql-general по дате отправления: