Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U6Ml3-0001Ar-7l for pgsql-performance@arkaria.postgresql.org; Fri, 15 Feb 2013 14:59:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U6Ml2-0005Kl-GB for pgsql-performance@arkaria.postgresql.org; Fri, 15 Feb 2013 14:59:24 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U6Ml1-0005Kf-36 for pgsql-performance@postgresql.org; Fri, 15 Feb 2013 14:59:23 +0000 Received: from nm39.bullet.mail.bf1.yahoo.com ([72.30.239.69]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U6Mkw-0000CW-Nb for pgsql-performance@postgresql.org; Fri, 15 Feb 2013 14:59:21 +0000 Received: from [98.139.215.141] by nm39.bullet.mail.bf1.yahoo.com with NNFMP; 15 Feb 2013 14:59:17 -0000 Received: from [98.139.212.210] by tm12.bullet.mail.bf1.yahoo.com with NNFMP; 15 Feb 2013 14:59:17 -0000 Received: from [127.0.0.1] by omp1019.mail.bf1.yahoo.com with NNFMP; 15 Feb 2013 14:59:17 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 380267.48770.bm@omp1019.mail.bf1.yahoo.com Received: (qmail 19736 invoked by uid 60001); 15 Feb 2013 14:59:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1360940357; bh=TS+NZ6RxLhzYnlxMdhlNa7Iqd6pg9KLaF8Dg7ynstgQ=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=xXIRgTd5Tu8ok9HJZ0pslDTU4Zjy9sldNijJxar7fdYKFgkzqPr7JTTDr7n57tJ1G05BHmu0QEiT1oDV8tnCqRNAQb4q6wcZEzfBCb9e2vyFuLM4k/JAiVBKYQ7fvx+ByiMmvHMGw09cACB+Zk35elB99NPZ7L/jQjJlvlqzKqw= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Q+7FhoTgldCXLEfp3UM4r8VN8YigQVku3/jlobTbo+lXYZ9N/6QHzbQXAH9pk41Lb5l3dNWljfYvqLzuvNK5HWLdnoNooz48HTiNdHZt+yDxM2oiqW+lPKJk7hZAPskj3KwO+68pYl4tQpIx9PvVO+d9hSd4Bw9zyZQqRiyH9cc=; X-YMail-OSG: podaA7sVM1lD8yuTvcna4_YOMBpnpkqOsQx.rB2L5T38GWJ a74bsJtKCC1s_KXk0Q925FdBPxCMklsajLb1cypli1KoTPJi.GlC3CS3FcPa Fg6ELgi8tqIH3FQKbrWqaubJPPNqb.CKaFoE7kt0oydxc7hWB57t8gijnRnc aLgM0lDkOqF84jyLOr9v3AEaui_P_HBWOx78nT9B8ZjRsm0R2RxX6DdC444Y PL7eDg0tZvpAtksCsLhfTPubJIN9Uq4ZOQzkFvXkO.Op2LZl8OqnAHAfTubd GU_eAIb2vwxTwX9tRfqronkdT7V.lpqz1LiUbpX3rNiV2KeQXnL0GqygVrYO jYVI2c.44BsscIZT_ZakUTEU9Uq6.lw8hXqjafJMT4h3VguxX9OCkS13D5Qi xKROiuqU3Dscd9YBg9ua02oUkjGtycLlhsXyJdFimav5_BImq2jDPuhj7FaI fMgYod.MZlkQdNmiARfyWprIQYUEP5UyQKQKGTV7Pg9qMRKDhzHo2AXTGbnx .yld4kz_ts0pFCDo8rWWCwQ4eHx9JMiq.MJWGeHRMXwy.4_IKvbyZW65l2rS q4KawJgNGymHjRgLWeZTHS3Ls0R9eD4V2vQv.kOI.6Uy9gopMNm7.wTes654 jSAWlgWsh7GHQhoADhbZoGXBErK4PFdseKFTeigSVWnOag4exNC52XA2OAbS HfBM9VsjHurW4V_uQULVPXYIiTOF5t4wKzyI8 Received: from [76.255.18.237] by web162905.mail.bf1.yahoo.com via HTTP; Fri, 15 Feb 2013 06:59:17 PST X-Rocket-MIMEInfo: 001.001, RmxvcmlhbiBTY2hyw7ZjayA8ZnNjaHJvZWNrQGF5Y2FuLmRlPiB3cm90ZToKCj4gVVBEQVRFIEJhY2t1cEZpbGVzCj7CoMKgIFNFVCBuVGFwZU5yPTAsIG5BRklPQ291bnRlcj0wLCBuQmxvY2tDb3VudGVyPTAsCj7CoMKgwqDCoMKgwqAgY1N0YXR1cz0nTkVXJzo6U3RhdHVzVCwgYk9uU2V0Qmx1ZT1mYWxzZSwKPsKgwqDCoMKgwqDCoCBiT25TZXRZZWxsb3c9ZmFsc2UsIG5MYXN0QmFja3VwVFM9ICcwMDAxLTAxLTAxIDAwOjAwOjAwJwo.wqDCoCBXSEVSRSBjU3RhdHVzPSdORVcnIE9SIGNTdGF0dXM9J1dSSVQBMAEBAQE- X-Mailer: YahooMailWebService/0.8.133.508 References: <511E469F.70308@aycan.de> Message-ID: <1360940357.13532.YahooMailNeo@web162905.mail.bf1.yahoo.com> Date: Fri, 15 Feb 2013 06:59:17 -0800 (PST) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Very slow update statement on 40mio rows To: =?iso-8859-1?Q?Florian_Schr=F6ck?= , "pgsql-performance@postgresql.org" In-Reply-To: <511E469F.70308@aycan.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Florian Schr=F6ck wrote: > UPDATE BackupFiles >=A0=A0 SET nTapeNr=3D0, nAFIOCounter=3D0, nBlockCounter=3D0, >=A0=A0=A0=A0=A0=A0 cStatus=3D'NEW'::StatusT, bOnSetBlue=3Dfalse, >=A0=A0=A0=A0=A0=A0 bOnSetYellow=3Dfalse, nLastBackupTS=3D '0001-01-01 00:0= 0:00' >=A0=A0 WHERE cStatus=3D'NEW' OR cStatus=3D'WRITING' OR cStatus=3D'ONTAPE'; > > Explain analyze: http://explain.depesz.com/s/8y5 > The statement takes 60-90 minutes. The EXPLAIN ANALYZE at that URL shows a runtime of 3 minutes and 41 seconds. > I tried to optimize the settings but until now without success. > > Can we optimize this update statement somehow? Do you have any > other ideas? Are there any rows which would already have the values that you are setting?=A0 If so, it would be faster to skip those by using this query: UPDATE BackupFiles =A0 SET nTapeNr=3D0, nAFIOCounter=3D0, nBlockCounter=3D0, =A0=A0=A0=A0=A0 cStatus=3D'NEW'::StatusT, bOnSetBlue=3Dfalse, =A0=A0=A0=A0=A0 bOnSetYellow=3Dfalse, nLastBackupTS=3D '0001-01-01 00:00:00' =A0 WHERE (cStatus=3D'NEW' OR cStatus=3D'WRITING' OR cStatus=3D'ONTAPE') =A0=A0=A0 AND (nTapeNr <> 0 OR nAFIOCounter <> 0 OR nBlockCounter <> 0 =A0=A0=A0=A0=A0=A0=A0=A0 OR cStatus <> 'NEW'::StatusT =A0=A0=A0=A0=A0=A0=A0=A0 OR bOnSetBlue IS DISTINCT FROM false =A0=A0=A0=A0=A0=A0=A0=A0 OR bOnSetYellow IS DISTINCT FROM false =A0=A0=A0=A0=A0=A0=A0=A0 OR nLastBackupTS <> '0001-01-01 00:00:00'); Another way to accomplish this is with the suppress_redundant_updates_trigger() trigger function: http://www.postgresql.org/docs/9.2/interactive/functions-trigger.html --=20 Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance