Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 8A99B2E004A for ; Wed, 9 Apr 2008 19:26:55 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 33367-09 for ; Wed, 9 Apr 2008 19:26:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from h07.llord.com (unknown [195.140.142.194]) by developer.postgresql.org (Postfix) with ESMTP id D713D2E0047 for ; Wed, 9 Apr 2008 19:26:52 -0300 (ADT) Received: from par69-8-88-161-102-87.fbx.proxad.net ([88.161.102.87] helo=apollo13.peufeu.com) by h07.llord.com with esmtpa (Exim 4.68) (envelope-from ) id 1Jjikk-0006Ez-Jx; Thu, 10 Apr 2008 00:26:50 +0200 Date: Thu, 10 Apr 2008 00:31:00 +0200 To: "John Beaver" , pgsql-performance@postgresql.org Subject: Re: large tables and simple "= constant" queries using indexes From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <47FD2DF3.80500@gmail.com> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: <47FD2DF3.80500@gmail.com> User-Agent: Opera Mail/9.24 (Linux) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - h07.llord.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - peufeu.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.965 tagged_above=0 required=5 tests=AWL=0.865, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200804/116 X-Sequence-Number: 29609 > Hi, I've started my first project with Postgres (after several years o= f = > using Mysql), and I'm having an odd performance problem that I was = > hoping someone might be able to explain the cause of. > > ----My query---- > - select count(*) from gene_prediction_view where gene_ref =3D 523= > - takes 26 seconds to execute, and returns 2400 (out of a total of= = > 15 million records in the table) > ---My problem--- > Using a single-column index to count 2400 records which are exactl= y = > one constant value doesn't sound like something that would take 26 = > seconds. What's the slowdown? Any silver bullets that might fix this? * Please post an EXPLAIN ANALYZE of your query which will allow to choo= se = between these two options : - If Postgres uses a bad plan (like a seq scan), you need to up the = statistics for this column - If you get the correct plan (index scan or bitmap index scan) then it= = is likely that postgres does one disk seek per row that has to be counte= d. = 26 seconds for 2400 rows would be consistent with a 10ms seek time. The = = unmistakable sign is that re-running the query will result in a very fas= t = runtime (I'd say a couple ms for counting 2400 rows if no disk IO is = involved).