X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1BA0CD1B19A for ; Sat, 17 Jul 2004 01:43:11 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92908-10 for ; Sat, 17 Jul 2004 04:43:07 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 03C15D1B170 for ; Sat, 17 Jul 2004 01:43:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i6H4h4uj001581; Sat, 17 Jul 2004 00:43:05 -0400 (EDT) To: Litao Wu Cc: pgsql-performance@postgresql.org Subject: Re: same plan, different time In-reply-to: <20040716213630.27909.qmail@web13125.mail.yahoo.com> References: <20040716213630.27909.qmail@web13125.mail.yahoo.com> Comments: In-reply-to Litao Wu message dated "Fri, 16 Jul 2004 14:36:30 -0700" Date: Sat, 17 Jul 2004 00:43:04 -0400 Message-ID: <1580.1090039384@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/114 X-Sequence-Number: 7505 Litao Wu 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