X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 29EE15347E for ; Thu, 12 May 2005 13:15:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72028-07 for ; Thu, 12 May 2005 16:14:55 +0000 (GMT) Received: from mail.liquidcore.com (mail.liquidcore.net [68.17.96.60]) by svr1.postgresql.org (Postfix) with ESMTP id 040DB53421 for ; Thu, 12 May 2005 13:14:54 -0300 (ADT) Received: (from root@localhost) by mail.liquidcore.com (8.13.1/8.12.10) id j4CGF6uQ023894; Thu, 12 May 2005 11:15:06 -0500 Received: from [192.168.0.81] (ppasalalinux.nqadmin.com [192.168.0.81]) by mail.liquidcore.com (8.13.1/8.12.10) with ESMTP id j4CGF5Xm023859; Thu, 12 May 2005 11:15:05 -0500 Message-ID: <428381C3.80205@nqadmin.com> Date: Thu, 12 May 2005 11:18:11 -0500 From: Prasanth Reply-To: dbadmin@nqadmin.com User-Agent: Mozilla Thunderbird 1.0.2-1.3.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: pgsql-admin@postgresql.org Subject: Re: Query Plan - Index Scan & Seq Scan References: <428370AC.3070207@nqadmin.com> <886.1115910870@sss.pgh.pa.us> <428379E0.4010709@nqadmin.com> <2052.1115913920@sss.pgh.pa.us> In-Reply-To: <2052.1115913920@sss.pgh.pa.us> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-scanner: scanned for malicious content X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.051 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200505/157 X-Sequence-Number: 17586 code data type is int2. I am sorry that I did not mention the version number I am using 7.4.7. Thanks, -Prasanth. Tom Lane wrote: > Prasanth writes: > >>A where condition I always use is shown below. This is bringing down the number >>of rows from 6.5m to 1210. I have an index on code also. Even here it is going >>for seq scan. > > >>EXPLAIN ANALYZE SELECT count(*) fROM a where Code >2; >> QUERY PLAN >>------------------------------------------------------------------------------------------------------------------------------- >> Aggregate (cost=141321.09..141321.09 rows=1 width=0) (actual >>time=6454.063..6454.064 rows=1 loops=1) >> -> Seq Scan on a (cost=0.00..141318.40 rows=1076 width=0) (actual >>time=15.687..6453.292 rows=1210 loops=1) >> Filter: (code > 2) >> Total runtime: 6454.140 ms >>(4 rows) > > > I'm going to hazard a guess that "code" is not of type integer, and that > you're using a pre-8.0 PG release. Cross-type comparisons are not > indexable before 8.0, so you need to cast the integer constant 2 to > whatever type "code" is. > > regards, tom lane > >