Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 5BD079FA37A for ; Thu, 28 Jun 2007 02:37:36 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 77485-01 for ; Thu, 28 Jun 2007 02:37:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by postgresql.org (Postfix) with ESMTP id 27ACC9FA306 for ; Thu, 28 Jun 2007 02:37:28 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis), id 0ML31I-1I3mh42H2Y-0004Cz; Thu, 28 Jun 2007 07:37:26 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1I3mh3-0005xm-00 for pgsql-performance@postgresql.org; Thu, 28 Jun 2007 07:37:25 +0200 Date: Thu, 28 Jun 2007 07:37:25 +0200 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: update query taking too long Message-ID: <20070628053724.GB22066@a-kretschmer.de> References: <46834124.5010600@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46834124.5010600@gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX19VvqbYYeOWeZkcCPc0VOoxbpyahIgeafJTeq7 T4zjz3r5WQynNpPE3EdswNp3d/h7LmEj77lwV2XBVjmx/H4Qgt KMl8bmQI2RWem839vD45b8HcvT3Vq/w X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/610 X-Sequence-Number: 25643 am Thu, dem 28.06.2007, um 15:03:32 +1000 mailte Chris folgendes: > Hi all, > > I'm trying to do an update of a reasonably large table and it's taking > way too long so I'm trying to work out why and if I need to tweak any > settings to speed it up. > > The table is around 3.5 million records. > > The query is > > update table set domainname=substring(emailaddress from position('@' in > emailaddress)); I think, this is a bad idea. Because, first, you have 2 columns with nearly identical data (mailaddres includes the domain and a extra domain field) And, after the UPDATE you have every row twice, because of MVCC: the live tuple and a dead tuple. > Any pointers about settings etc are most welcome. I think, you should better use a VIEW. CREATE VIEW my_view_on_table as SELECT mailaddres, substring(...) as domain, ... or, use the substring(...) in your regular queries instead the extra column. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net