Re: same plan, different time

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Litao Wu <litaowu(at)yahoo(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: same plan, different time
Date: 2004-07-17 04:43:04
Message-ID: 1580.1090039384@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Josh Berkus 2004-07-18 00:02:20 Re: Scaling with lazy index updates
Previous Message Fred Moyer 2004-07-17 03:30:34 Scaling with lazy index updates