Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 33A2A9FA19B for ; Wed, 6 Dec 2006 15:20:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 79062-08 for ; Wed, 6 Dec 2006 15:20:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id CBD689FA0FB for ; Wed, 6 Dec 2006 15:20:46 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 8FEA0353FA; Wed, 6 Dec 2006 11:20:44 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8DFE735391; Wed, 6 Dec 2006 11:20:44 -0800 (PST) Date: Wed, 6 Dec 2006 11:20:44 -0800 (PST) From: Stephan Szabo To: Rafael Martinez Cc: pgsql-performance@postgresql.org Subject: Re: Problems with an update-from statement and pg-8.1.4 In-Reply-To: <1165432244.9606.18.camel@bbking.linux> Message-ID: <20061206111630.R8187@megazone.bigpanda.com> References: <1165432244.9606.18.camel@bbking.linux> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/142 X-Sequence-Number: 22198 On Wed, 6 Dec 2006, Rafael Martinez wrote: > We are having some problems with an UPDATE ... FROM sql-statement and > pg-8.1.4. It takes ages to finish. The problem is the Seq Scan of the > table 'mail', this table is over 6GB without indexes, and when we send > thousands of this type of statement, the server has a very high iowait > percent. > > How can we get rid of this Seq Scan? > > I send the output of an explain and table definitions: > ------------------------------------------------------------------------- > > mailstats=# EXPLAIN update mail SET spamscore = '-5.026' FROM mail m, > mail_received mr where mr.mail_id = m.mail_id AND mr.queue_id = > '1GrxLs-0004N9-I1' and mr.mailhost = '129.240.10.47'; I don't think this statement does what you expect. You're ending up with two copies of mail in the above one as "mail" and one as "m". You probably want to remove the mail m in FROM and use mail rather than m in the where clause.