X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 0FE1111F620D for ; Tue, 4 Apr 2006 16:48:51 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92867-06 for ; Tue, 4 Apr 2006 16:48:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id DA4BA11F61CE for ; Tue, 4 Apr 2006 16:48:48 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Tue, 4 Apr 2006 19:48:48 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 04 Apr 2006 14:48:48 -0500 Subject: Re: Query runs too long for indexed tables From: Scott Marlowe To: Andrus Cc: pgsql-performance@postgresql.org In-Reply-To: References: Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1144180128.32266.56.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Tue, 04 Apr 2006 14:48:48 -0500 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.141 required=5 tests=[AWL=0.140, UNPARSEABLE_RELAY=0.001] X-Spam-Score: 0.141 X-Spam-Level: X-Archive-Number: 200604/49 X-Sequence-Number: 18133 On Tue, 2006-04-04 at 14:37, Andrus wrote: > I have relatively small tables (toode and rid) in fast server. > Both tables are indexed on toode field. > > Following query takes long time to run. > toode field type is char(20). It is difficult to change this field type. > > Any idea how to speed up this query ? > > UPDATE firma1.rid SET toode=NULL > WHERE toode IS NOT NULL AND > toode NOT IN (SELECT TOODE FROM firma1.TOODE); > > Query returned successfully: 0 rows affected, 594813 ms execution time. > > explain window shows: > > Seq Scan on rid (cost=2581.07..20862553.77 rows=51848 width=1207) > Filter: ((toode IS NOT NULL) AND (NOT (subplan))) > SubPlan > -> Materialize (cost=2581.07..2944.41 rows=14734 width=84) > -> Seq Scan on toode (cost=0.00..2350.34 rows=14734 width=84) Let me guess, you've updated it a lot and aren't familiar with Vacuum? run a vacuum full on your database. schedule a vacuum (plain one) to run every so often (hours or days are a good interval for most folks) If that's NOT your problem, then please, let us know.