Re: intelligence in writing a query ...
От | Tom Lane |
---|---|
Тема | Re: intelligence in writing a query ... |
Дата | |
Msg-id | 4891.991258533@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | intelligence in writing a query ... (The Hermit Hacker <scrappy@hub.org>) |
Ответы |
Re: intelligence in writing a query ...
|
Список | pgsql-hackers |
The Hermit Hacker <scrappy@hub.org> writes: > 2EXPLAIN SELECT distinct s.gid, s.created, count(i.title) AS images > FROM status s LEFT JOIN images i ON (s.gid = i.gid AND i.active), relationship_wanted rw > WHERE s.active AND s.status != 0 > AND EXISTS ( SELECT gid > FROM relationship_wanted > WHERE gender = 1 ) > AND EXISTS ( SELECT gid > FROM personal_data > WHERE gender = 0 > AND ( ( age('now', dob) > '26 years' ) AND ( age('now', dob) < '46 years' ) ) > AND country IN ( 'US' ) ) > GROUP BY s.gid,s.created > ORDER BY images desc; I don't understand what you're trying to do here. The inner SELECTs aren't dependent on anything in the outer query, so what are they for? > ... status and > personal_data have a 1-to-1 relationship, Then why have two tables? Merge them into one table and save yourself a join. Also, since status.gid is (I assume) unique, what's the use of the DISTINCT clause at the top level? Seems like that's costing you a useless sort & unique pass ... regards, tom lane
В списке pgsql-hackers по дате отправления: