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 235BA9DC859 for ; Fri, 3 Mar 2006 05:47:08 -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 11118-04 for ; Fri, 3 Mar 2006 05:47:09 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id A59AA9DC891 for ; Fri, 3 Mar 2006 05:47:05 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id k239l0O2080278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Mar 2006 02:47:03 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id k239l07x036226; Fri, 3 Mar 2006 02:47:00 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id k239kxr9036225; Fri, 3 Mar 2006 02:46:59 -0700 (MST) (envelope-from mfuhr) Date: Fri, 3 Mar 2006 02:46:59 -0700 From: Michael Fuhr To: "Gregory S. Williamson" Cc: Bryce Nesbitt , pgsql-sql@postgresql.org Subject: Re: Sequential scan where Index scan expected (update) Message-ID: <20060303094659.GA36052@winnie.fuhr.org> References: <71E37EF6B7DCC1499CEA0316A2568328024BC055@loki.wc.globexplorer.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <71E37EF6B7DCC1499CEA0316A2568328024BC055@loki.wc.globexplorer.net> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.122 required=5 tests=[AWL=0.122] X-Spam-Score: 0.122 X-Spam-Level: X-Archive-Number: 200603/64 X-Sequence-Number: 24410 On Thu, Mar 02, 2006 at 11:37:53PM -0800, Gregory S. Williamson wrote: > It seems unlikely but maybe try an explict cast for the thing_id call, e.g. > explain update xx_thing_event set thing_color='foo' where > thing_event_id=10000::bigint; The server is pre-8.0 so it's likely that this is indeed the problem. Unfortunately the table that was shown in the \d output (xx_thing) isn't the same table as in the update command (xx_thing_event) so we can only guess that thing_event_id is a bigint based on what xx_thing looks like. > It may also be that 5842 rows is enough that the planner decides > it is faster to do a sequential scan that the busier index scan > (read index, get data row, versus just reading all the necessary > pages in one faster sequential scan). [...] > QUERY PLAN > --------------------------------------------------------------------- > Seq Scan on xx_thing_event (cost=0.00..5842.48 rows=1 width=110) > Filter: (thing_event_id = 10000) > (2 rows) The 5842.48 figure isn't a row count, it's a cost estimate that includes the number of pages and rows in the file. The row count estimate is 1 row; if the cost estimate for a sequential scan is 5842.48 then an index scan to fetch one row would surely be faster. If thing_event_id is a bigint and has an index then casting the value to bigint should result in an index scan. Another way would be to quote the value: UPDATE xx_thing_event SET thing_color = 'foo' WHERE thing_event_id = '10000'; -- Michael Fuhr