Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 99ADF2E2DBD for ; Wed, 28 Nov 2007 12:00:11 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 23903-05 for ; Wed, 28 Nov 2007 12:00:08 -0400 (AST) Received: from globalrelay.com (mail1.globalrelay.com [204.92.49.200]) by postgresql.org (Postfix) with ESMTP id BBE9D2E2DBC for ; Wed, 28 Nov 2007 12:00:07 -0400 (AST) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway Received: from [63.231.179.94] (HELO davedell) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 165874347; Wed, 28 Nov 2007 16:00:06 +0000 From: "Dave Dutcher" To: "'tmp'" Cc: 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> Subject: Re: Query only slow on first run Date: Wed, 28 Nov 2007 10:00:05 -0600 Message-ID: <05e801c831d7$bea1bee0$8e00a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcgxyGSJrLlEAxGETPqu9OJQhD5dJAACL/qA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 In-Reply-To: <474CBF98.6070508@amossen.dk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/354 X-Sequence-Number: 27769 > -----Original Message----- > From: tmp > We have primarily two tables of interest here: questions > (~100k rows) and posts (~400k rows). Each post refers to a > question, but only the "posts" rows for which the > corresponding "question.status = 1" are relevant. This > reduces the number of relevant question rows to about 10k. Earlier you said only a small subset of questions have a status of 1, so I assumed you meant like 100 not 10k :) 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.