Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-performance by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group