Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6DFC94BB8EB for ; Wed, 4 Apr 2012 13:35:02 -0300 (ADT) Received: from [2001:1528:137::f1] (helo=mail.gransy.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SFTAi-0004Xn-37 for pgsql-performance@postgresql.org; Wed, 04 Apr 2012 16:35:01 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id 604DF508892 for ; Wed, 4 Apr 2012 18:34:47 +0200 (CEST) Received: from mail.gransy.com ([82.208.29.194]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id 3pSn5W8+xaH1 for ; Wed, 4 Apr 2012 18:34:47 +0200 (CEST) Received: by mail.gransy.com (Postfix, from userid 5000) id 4F76E5088A7; Wed, 4 Apr 2012 18:34:47 +0200 (CEST) Received: from [192.168.1.237] (ip-78-45-133-255.net.upcbroadband.cz [78.45.133.255]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id 37C8D508892 for ; Wed, 4 Apr 2012 18:34:47 +0200 (CEST) Message-ID: <4F7C7827.7080705@fuzzy.cz> Date: Wed, 04 Apr 2012 18:34:47 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120312 Thunderbird/11.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: about multiprocessingmassdata References: <2012040423524938620013@gmail.com> In-Reply-To: <2012040423524938620013@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:1528:137::f1 (failed) X-Pg-Spam-Score: -1.1 (-) X-Archive-Number: 201204/45 X-Sequence-Number: 46691 On 4.4.2012 17:52, superman0920 wrote: > Hi list! > > i have a table which has 8500000 rows records. i write a java program to > update these records. > i use 100 threads to update the records. For example, thread-1 update > 1~85000 records; thread-2 update 85001~170000 and so on. > The update sql's aim is remove the space in the column and it is simple: > update poi set py=replace(py,' ','') where id=?; That's a very naive approach. It's very likely each thread will do an index scan for each update (to evaluate the 'id=?' condition. And that's going to cost you much more than you gain because index scans are quite CPU and I/O intensive. Simply update the whole table by UPDATE poi SET py = replace(py, ' ',''); Have you actually tried how this performs or did you guess 'it's definitely going to be very slow so I'll use multiple threads to make that faster'? If you really need to parallelize this, you need to do that differently - e.g. use 'ctid' to skip to update a whole page like this: UPDATE poi SET py = replace(py, ' ','') WHERE ctid >= '(n,0)'::tid AND ctid < '(n+1,0)'::tid AND; where 'n' ranges between 0 and number of pages the table (e.g. in pg_class). But try the simple UPDATE first, my guess is it's going to be much faster than you expect. Tomas