Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 808652E0139 for ; Wed, 13 Feb 2008 15:46:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 06260-04 for ; Wed, 13 Feb 2008 15:46:41 -0400 (AST) Received: from mail1.livedatagroup.com (mail1.livedatagroup.com [216.154.205.166]) by postgresql.org (Postfix) with ESMTP id 7AE3D2E0121 for ; Wed, 13 Feb 2008 15:46:44 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mail1.livedatagroup.com (Postfix) with ESMTP id 3DF18109951; Wed, 13 Feb 2008 14:46:43 -0500 (EST) Received: from mail1.livedatagroup.com ([192.168.3.224]) by localhost (mail1.livedatagroup.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04958-05; Wed, 13 Feb 2008 14:46:42 -0500 (EST) Received: from [192.168.2.134] (gw.livedatagroup.com [205.242.255.66]) by mail1.livedatagroup.com (Postfix) with ESMTP id 5706A10994A; Wed, 13 Feb 2008 14:46:42 -0500 (EST) Message-ID: <47B34921.1040507@livedatagroup.com> Date: Wed, 13 Feb 2008 14:46:41 -0500 From: Pallav Kalva User-Agent: Thunderbird 2.0.0.6 (X11/20070728) MIME-Version: 1.0 To: Richard Huxton CC: "Dean Gibson (DB Administrator)" , pgsql-performance@postgresql.org Subject: Re: Optimizing No matching record Queries References: <47B2112C.5070707@livedatagroup.com> <47B234C1.1090707@ultimeth.com> <47B2B058.7020804@archonet.com> In-Reply-To: <47B2B058.7020804@archonet.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at livedatagroup.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/148 X-Sequence-Number: 28690 Thanks! for all your replies, I tried increasing the statistics on fklistingsourceid to 1000 it made any difference. Then I created an index on (fklistingsourceid,entrydate) it helped and it was fast. This index would fix this problem but in general I would like to know what if there are queries where it does "index scan backwards" and there is no "order by clause" and the query is still bad ? Would there be a case like that or the planner uses index scan backwards only when use order by desc also. Richard Huxton wrote: > Dean Gibson (DB Administrator) wrote: >> The questions are: >> >> 1. Why in the planner scanning the entire idx_listing_entrydate, when >> I'd think it should be scanning the entire >> pk_listingstatus_listingstatusid ? > > It's looking at the ORDER BY and sees that the query needs the 10 most > recent, so tries searching by date. That's sensible where you are > going to have a lot of matches for fklistingsourceid. > > Which suggests that statistics for "fklistingsourceid" aren't high > enough, like Greg suggested. If that doesn't help, the index on > (fklistingsourceid,entrydate) that Stephen might well do so. > >> 2. Why is "Index Scan using pk_listingstatus_listingstatusid on >> listingstatus listingsta1_ (cost=0.00..0.27 rows=1 width=4) (never >> executed)" ? > > Because nothing comes out of the first index-scan. >