Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id DF9162E2E9B for ; Wed, 28 Nov 2007 13:12:59 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 02622-05 for ; Wed, 28 Nov 2007 13:12:54 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 256332E0075 for ; Wed, 28 Nov 2007 13:12:55 -0400 (AST) 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 lASHCqOE002225; Wed, 28 Nov 2007 12:12:52 -0500 (EST) To: "Dave Dutcher" cc: "'tmp'" , pgsql-performance@postgresql.org Subject: Re: Query only slow on first run In-reply-to: <05e801c831d7$bea1bee0$8e00a8c0@tridecap.com> References: <20071127165543.GY11978@crankycanuck.ca> <23999.1196184368@sss.pgh.pa.us> <056501c83128$55d58a90$8e00a8c0@tridecap.com> <20071127233833.GA24031@uio.no> <15029.1196209554@sss.pgh.pa.us> <474CBF98.6070508@amossen.dk> <05e801c831d7$bea1bee0$8e00a8c0@tridecap.com> Comments: In-reply-to "Dave Dutcher" message dated "Wed, 28 Nov 2007 10:00:05 -0600" Date: Wed, 28 Nov 2007 12:12:52 -0500 Message-ID: <2224.1196269972@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/358 X-Sequence-Number: 27773 "Dave Dutcher" writes: > ... According to the explain analyze > there are only 646 rows in posts which match your criteria, so it does seem > like scanning posts first might be the right thing to do. No, that's not right. What the output actually shows is that only 646 posts rows were needed to produce the first 200 aggregate rows, which was enough to satisfy the LIMIT. The planner is evidently doing things this way in order to exploit the presence of the LIMIT --- if it had to compute all the aggregate results it would likely have picked a different plan. regards, tom lane