X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D67FF9DC82A for ; Fri, 3 Mar 2006 05:30:44 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 07935-07 for ; Fri, 3 Mar 2006 05:30:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx1.hive.is (scania.ipf.is [85.197.192.147]) by postgresql.org (Postfix) with SMTP id 5EF9E9DC81C for ; Fri, 3 Mar 2006 05:30:41 -0400 (AST) Received: (qmail 44664 invoked by uid 1010); 3 Mar 2006 09:30:57 -0000 Received: from 85.197.216.186 by scania.ipf.is (envelope-from , uid 1009) with qmail-scanner-1.25-st-qms (clamdscan: 0.88/1283. spamassassin: 3.1.0. perlscan: 1.25-st-qms. Clear:RC:1(85.197.216.186):SA:0(-4.1/4.0):. Processed in 0.36698 secs); 03 Mar 2006 09:30:57 -0000 X-Antivirus-HIVE-Mail-From: gnari@hive.is via scania.ipf.is X-Antivirus-HIVE: 1.25-st-qms (Clear:RC:1(85.197.216.186):SA:0(-4.1/4.0):. Processed in 0.36698 secs Process 44657) Received: from dsl-216-186.hive.is (HELO ?192.168.1.34?) (85.197.216.186) by mx1.hive.is with SMTP; 3 Mar 2006 09:30:56 -0000 Subject: Re: Sequential scan where Index scan expected (update) From: Ragnar To: Bryce Nesbitt Cc: pgsql-sql@postgresql.org In-Reply-To: <4407F031.6050706@obviously.com> References: <244004377.20060302124132@isb.com.pl> <2873.1141312882@sss.pgh.pa.us> <4407F031.6050706@obviously.com> Content-Type: text/plain Date: Fri, 03 Mar 2006 09:31:37 +0000 Message-Id: <1141378297.18656.119.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.153 required=5 tests=[AWL=0.153] X-Spam-Score: 0.153 X-Spam-Level: X-Archive-Number: 200603/63 X-Sequence-Number: 24409 On fim, 2006-03-02 at 23:28 -0800, Bryce Nesbitt wrote: > I'm getting sequential scans (and poor performance), on scans using my > primary keys. This is an older postgres. > Can anyone help figure out why? > > > demo=# \d xx_thing > Table "public.xx_thing" > Column | Type | Modifiers > -------------------------+-----------------------------+----------- > thing_id | bigint | not null ... > demo=# explain update xx_thing_event set thing_color='foo' where > thing_event_id=10000; > QUERY PLAN > --------------------------------------------------------------------- > Seq Scan on xx_thing_event (cost=0.00..5842.48 rows=1 width=110) ... > demo=# select * from version(); > version > ---------------------------------------------------------------------------------------------------------- > PostgreSQL 7.4.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3 try one of: ... WHERE thing_event_id=10000::bigint ... WHERE thing_event_id='10000' or upgrade to >= 8.0 your problem is that the 10000 in 'thing_event_id=10000' is parsed as an integer but not a bigint, so the planner does not find a matching index. so you either have to scpecify ::bigint or ::int8 in the query or quote the number, which will cause postgres to cast it to the column's type. if you try ... WHERE thing_event_id=10000000000 you will see the index used because this number cannot be a int4 so is parsed as a bigint. newer versions of Postgresql can deal with this. gnari