Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 88C749FA552 for ; Wed, 31 Oct 2007 01:05:54 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 64868-05 for ; Wed, 31 Oct 2007 01:05:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 4FCA79F924D for ; Wed, 31 Oct 2007 01:05:46 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l9V45gl0008482; Wed, 31 Oct 2007 00:05:42 -0400 (EDT) To: cluster cc: pgsql-performance@postgresql.org Subject: Re: Two fast queries get slow when combined In-reply-to: References: Comments: In-reply-to cluster message dated "Tue, 30 Oct 2007 21:48:16 +0100" Date: Wed, 31 Oct 2007 00:05:42 -0400 Message-ID: <8481.1193803542@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/370 X-Sequence-Number: 27392 cluster writes: > Queries and output from EXPLAIN ANALYZE can be seen here with some > syntax highlighting: > http://rafb.net/p/BJIW4p69.html You are lying to us about how those queries were posed to Postgres (and no I don't feel a need to explain how I know). In future please present the full truth about what you are doing, not a simplification that you think is sufficient. But I think the short answer to your question is that query 1 is fast because it need only select the first 50 rows in some ordering, and query 2 is fast because it need only select the first 50 rows in some ordering, but they are not the same ordering so the join query doesn't get to exploit that shortcut. regards, tom lane