Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5EBDD634138 for ; Thu, 22 Jul 2010 05:16:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 64628-03 for ; Thu, 22 Jul 2010 08:16:40 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.10]) by mail.postgresql.org (Postfix) with ESMTP id 91D93632BFB for ; Thu, 22 Jul 2010 05:16:40 -0300 (ADT) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MNh30-1OhsJ23VZy-006hgi; Thu, 22 Jul 2010 10:16:38 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1ObqxJ-0006EU-00 for pgsql-performance@postgresql.org; Thu, 22 Jul 2010 10:16:37 +0200 Date: Thu, 22 Jul 2010 10:16:37 +0200 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: why index is not working in < operation? Message-ID: <20100722081637.GD10348@a-kretschmer.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V02:K0:IyoMEJgZgVRA8FFY2jXV+uNO+u9PZJVUcdnhghh0g1J 2zmgAOTsXI9eRwgnmroQ/L4FF33Lul04s6JzkhuWuimxC4WTg7 NmlqUlcX9//IHpvCRkPBy7d6CSzDgKCXt8rPwjnZD4QnbGR5AX nrR2BvF33QTilX1HOhko1QRNuVCj6MSIN1sxD3k2GGO3mLB6ZB NtI4VwHxNVIOPoZutZB2A== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.81 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001, T_FRT_CONTACT=0.01 X-Spam-Level: X-Archive-Number: 201007/315 X-Sequence-Number: 39704 In response to AI Rumman : > I have a table. > > \d email_track > Table "public.email_track" >  Column |  Type   |     Modifiers      > --------+---------+-------------------- >  crmid  | integer | not null default 0 >  mailid | integer | not null default 0 >  count  | integer | > Indexes: >     "email_track_pkey" PRIMARY KEY, btree (crmid, mailid) CLUSTER >     "email_track_count_idx" btree (count) > > > explain analyze select * from email_track where count > 10 ; >                                                                      QUERY > PLAN                                                                     > ---------------------------------------------------------------------------------------------------------------------------------------------------- >  Bitmap Heap Scan on email_track  (cost=12.79..518.05 rows=1941 width=12) > (actual time=0.430..3.047 rows=1743 loops=1) >    Recheck Cond: (count > 10) >    ->  Bitmap Index Scan on email_track_count_idx  (cost=0.00..12.79 rows=1941 > width=0) (actual time=0.330..0.330 rows=1743 loops=1) >          Index Cond: (count > 10) >  Total runtime: 4.702 ms > (5 rows) > > explain analyze select * from email_track where count < 10000 ; >                                                             QUERY > PLAN                                                            > ---------------------------------------------------------------------------------------------------------------------------------- >  Seq Scan on email_track  (cost=0.00..1591.65 rows=88851 width=12) (actual time > =0.011..118.499 rows=88852 loops=1) >    Filter: (count < 10000) >  Total runtime: 201.206 ms > (3 rows) > > I don't know why index scan is not working for count < 10000 operation. > Any idea please. How many rows contains the table? I think, with your where-condition count < 10000 roughly the whole table in the result, right? In this case, a seq-scan is cheaper than an index-scan. Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99