Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 282A163529F for ; Tue, 6 Apr 2010 15:53:44 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 96990-02-7 for ; Tue, 6 Apr 2010 18:53:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pw0-f46.google.com (mail-pw0-f46.google.com [209.85.160.46]) by mail.postgresql.org (Postfix) with ESMTP id EFF11635502 for ; Tue, 6 Apr 2010 15:33:52 -0300 (ADT) Received: by pwj9 with SMTP id 9so208755pwj.19 for ; Tue, 06 Apr 2010 11:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=4scKScKofvGZEU5Ia3Ck3b4Jd5S5jtz6roW87Mc2PPA=; b=iKiyh7WlLXfpzMf7MXpRUAjBV20ZTnHZlBapAp8QnztgiiJk//kvRwYkh3NZRAFPaW 1N4rYtuxnJua7cyTQ4m1siuawBmC79U09u5TY8A8qBPj1otCEHHt+3b8H3BfZycccLkO fy/gjF3z+4J6b36zKJhXfPBY6sz1T5ybHhBdM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=o1h8r7SCK7WqtLLSGXFPiOS+CAxDirTBzdsGQFyTYX3Gt/Y4rzGFQAH0QTVUDElIRm 6vN9L70jja4BRAVL/YP9UY4BcpntpZnE6EFutRc1Ntal9ERTeUSu9A/5l0dimenFy+Cn mPuTJYEItlyXsG+7CZtTO2Oy52L42coBU70u4= MIME-Version: 1.0 Received: by 10.231.19.69 with HTTP; Tue, 6 Apr 2010 11:33:51 -0700 (PDT) In-Reply-To: References: Date: Tue, 6 Apr 2010 14:33:51 -0400 Received: by 10.143.21.30 with SMTP id y30mr490385wfi.127.1270578831806; Tue, 06 Apr 2010 11:33:51 -0700 (PDT) Message-ID: Subject: Re: LIMIT causes planner to do Index Scan using a less optimal index From: Robert Haas To: Joel Jacobson Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.27 tagged_above=-10 required=5 tests=AWL=-1.085, BAYES_40=-0.185 X-Spam-Level: X-Archive-Number: 201004/56 X-Sequence-Number: 38306 On Fri, Apr 2, 2010 at 2:19 PM, Joel Jacobson wrote: > Is this a bug?=A0I'm using version 8.4.1. It's not really a bug, but it's definitely not a feature either. > =A0Limit =A0(cost=3D0.00..43.46 rows=3D1 width=3D4) (actual time=3D1023.2= 13..1023.214 > rows=3D1 loops=3D1) > =A0=A0 -> =A0Index Scan using transactions_pkey on transactions > =A0(cost=3D0.00..493029.74 rows=3D11345 width=3D4) (actual time=3D1023.21= 2..1023.212 > rows=3D1 loops=3D1) > =A0=A0 =A0 =A0 =A0 Filter: ((accountid =3D 108) AND (currency =3D 'SEK'::= bpchar)) > =A0Total runtime: 1023.244 ms > (4 rows) The planner's idea here is that rows matching the filter criteria will be common enough that an index scan over transactions_pkey will find one fairly quickly, at which point the executor can return that row and stop. But it turns out that those rows aren't as common as the planner thinks, so the search takes a long time. ...Robert