Litao Wu <litaowu(at)yahoo(dot)com> writes:
> SELECT *
> FROM user U LEFT JOIN user_timestamps T USING
> (user_id), user_alias A
> WHERE U.user_id = A.user_id AND A.domain_id=7551070;
Ick. Try changing the join order, perhaps
SELECT *
FROM (user U JOIN user_alias A ON (U.user_id = A.user_id))
LEFT JOIN user_timestamps T USING (user_id)
WHERE A.domain_id=7551070;
As you have it, the entire LEFT JOIN has to be formed first,
and the useful restriction clause only gets applied later.
The fact that the case with 7551070 finishes quickly is just
blind luck --- the slow case is much more representative.
regards, tom lane