Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id C0E939FBE9E for ; Thu, 28 Jun 2007 03:15:19 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 54740-04 for ; Thu, 28 Jun 2007 03:15:11 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.181]) by postgresql.org (Postfix) with ESMTP id 70EDF9FB6FE for ; Thu, 28 Jun 2007 03:15:12 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so650954wah for ; Wed, 27 Jun 2007 23:15:10 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=XaDvsrGOUUwUxW+HiHR1roj0+YBm5w1qnfXCpyNfqW/8mqprmAc44ztu74RGNe0Gt94KL8z4H5cmwNP7XZmxnfCDzly9NpGDDud3BMmrdlZFlQwGiiSs445on4PihxwtqHGyNpXJXsqNShL51ncKOY1PzrLNhH/O50vznJcZ5oI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=tZjs9iigCqCdOd7JLOCOn5BOaCpBLFvCbKOg38WOGw8GAt7qJfAefaQlnEPpshgdWlb6m3xGnTllP00nxS3rtnIrdbA8443f9TLWlF203rgMo5rnBbAIewKztmhI4C06Z4uJF4cTORVuZNAghTMgCHH52xuh1tarVftnbHlpepQ= Received: by 10.114.123.1 with SMTP id v1mr1190665wac.1183011307228; Wed, 27 Jun 2007 23:15:07 -0700 (PDT) Received: from ?10.1.1.15? ( [203.217.18.65]) by mx.google.com with ESMTP id n20sm18427488pof.2007.06.27.23.15.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 27 Jun 2007 23:15:06 -0700 (PDT) Message-ID: <46835252.5070901@gmail.com> Date: Thu, 28 Jun 2007 16:16:50 +1000 From: Chris User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: Tom Lane CC: Pgsql performance Subject: Re: update query taking too long References: <46834124.5010600@gmail.com> <21072.1183009270@sss.pgh.pa.us> In-Reply-To: <21072.1183009270@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/612 X-Sequence-Number: 25645 Tom Lane wrote: > Chris writes: >> 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. > > Any foreign keys leading to or from that table? Nope :( > 3.5 million row updates are not exactly gonna be instantaneous anyway, > but only FK checks or really slow user-written triggers would make it > take upwards of an hour ... No triggers, functions. Table is pretty basic. I have a few indexes (one on the primary key, one on emailaddress etc) but the 'domainname' column is a new one not referenced by any of the indexes. FWIW (while the other update is still going in another window): select SUBSTRING(emailaddress FROM POSITION('@' IN emailaddress)) from table; Time: 28140.399 ms Is there a better way to write the update? I thought about something like this (but couldn't get it working - guess I don't have the right syntax): update t1 set domainname=(select id, SUBSTRING(emailaddress FROM POSITION('@' IN emailaddress)) from table t2) AS t2 where t1.id=t2.id -- Postgresql & php tutorials http://www.designmagick.com/