Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id A33389FA19B for ; Wed, 6 Dec 2006 15:53:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 15553-10 for ; Wed, 6 Dec 2006 15:53:40 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from smtp.blackducksoftware.com (nat.blackducksoftware.com [216.195.218.91]) by postgresql.org (Postfix) with ESMTP id 0BE2E9F9386 for ; Wed, 6 Dec 2006 15:53:40 -0400 (AST) Received: from localhost (gyro.blackducksoftware.com [127.0.0.1]) by smtp.blackducksoftware.com (Postfix) with ESMTP id 4112E5C43A3; Wed, 6 Dec 2006 14:53:46 -0500 (EST) Received: from smtp.blackducksoftware.com ([127.0.0.1]) by localhost (gyro.blackducksoftware.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 02805-02; Wed, 6 Dec 2006 14:53:45 -0500 (EST) Received: from [10.12.14.31] (tallen.blackducksoftware.com [10.12.14.31]) by smtp.blackducksoftware.com (Postfix) with ESMTP id A397E5C435F; Wed, 6 Dec 2006 14:53:45 -0500 (EST) Message-ID: <45772022.4050303@blackducksoftware.com> Date: Wed, 06 Dec 2006 14:55:14 -0500 From: Ted Allen User-Agent: Thunderbird 1.5.0.7 (X11/20060922) MIME-Version: 1.0 To: Stephan Szabo CC: Rafael Martinez , pgsql-performance@postgresql.org Subject: Re: Problems with an update-from statement and pg-8.1.4 References: <1165432244.9606.18.camel@bbking.linux> <20061206111630.R8187@megazone.bigpanda.com> In-Reply-To: <20061206111630.R8187@megazone.bigpanda.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Debian amavisd-new at blackducksoftware.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/143 X-Sequence-Number: 22199 Stephan Szabo wrote: > 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. > > ---------------------------(end of broadcast)--------------------------- > TIP 9: In versions below 8.0, the planner will ignore your desire to > choose an index scan if your joining column's datatypes do not > match > > Worse yet I think your setting "spamcore" for EVERY row in mail to '-5.026'. The above solution should fix it though. -- Ted * *