pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Litao Wu <litaowu@yahoo.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: same plan, different time
Date: Sat, 17 Jul 2004 00:43:04 -0400
Message-ID: <1580.1090039384@sss.pgh.pa.us> (raw)
In-Reply-To: <20040716213630.27909.qmail@web13125.mail.yahoo.com>
References: <20040716213630.27909.qmail@web13125.mail.yahoo.com>

Litao Wu <litaowu@yahoo.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



view thread (2+ messages)

Message-ID: <1580.1090039384@sss.pgh.pa.us>
Permalink:  ../1580.1090039384@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1580.1090039384@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, litaowu@yahoo.com
  Subject: Re: same plan, different time
  In-Reply-To: <1580.1090039384@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox