Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WuSSY-00039l-A9 for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2014 20:15:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WuSSX-0002nb-PY for pgsql-bugs@arkaria.postgresql.org; Tue, 10 Jun 2014 20:15:53 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1WuSSW-0002l6-FK for pgsql-bugs@postgresql.org; Tue, 10 Jun 2014 20:15:52 +0000 Received: from nm16-vm2.bullet.mail.ne1.yahoo.com ([98.138.91.92]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WuSSS-0004eW-Ue for pgsql-bugs@postgresql.org; Tue, 10 Jun 2014 20:15:50 +0000 Received: from [98.138.101.129] by nm16.bullet.mail.ne1.yahoo.com with NNFMP; 10 Jun 2014 20:15:47 -0000 Received: from [98.138.101.179] by tm17.bullet.mail.ne1.yahoo.com with NNFMP; 10 Jun 2014 20:15:47 -0000 Received: from [127.0.0.1] by omp1090.mail.ne1.yahoo.com with NNFMP; 10 Jun 2014 20:15:47 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 458977.53655.bm@omp1090.mail.ne1.yahoo.com Received: (qmail 49541 invoked by uid 60001); 10 Jun 2014 20:15:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1402431347; bh=08bGyij/UHOQEf3hK+dXmrXn9YMP1W0mLRDMkw7aBS0=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=SNTi/JKSbL2p12otssrD/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HNvbWUgYW1vdW50IG9mIGRhdGEKPi0gYWRkIG5ld19jb2x1bW4gKHdvcmtzIGluc3RhbnRlbHkpCj4tIGFkZCBhIHVuaXF1ZSBjb250cmFpbnQgb24gbmV3X2NvbHVtbgo.LSB1cGRhdGUgZGVtb190YWJsZSBzZXQgbmV3X2NvbHVtPW51bGw7IChxdWl0ZSBzbG93KQo.LT4gdGFrZXMgYSBsb25nIHRpbWU6IHNlZW1zIHRvIHJld3JpdGUgdGhlIHdob2xlIHRhYmxlCgpUaGlzIGlzIG5vdCBhIGIBMAEBAQE- X-Mailer: YahooMailWebService/0.8.190.668 References: <20140610183719.2589.93121@wrigleys.postgresql.org> Message-ID: <1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com> Date: Tue, 10 Jun 2014 13:15:47 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: BUG #10591: setting newly added columns to null is slow To: "eike@inter.net" , "pgsql-bugs@postgresql.org" In-Reply-To: <20140610183719.2589.93121@wrigleys.postgresql.org> 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-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "eike@inter.net" wrote: >- given demo_table with some amount of data >- add new_column (works instantely) >- add a unique contraint on new_column >- update demo_table set new_colum=3Dnull; (quite slow) >-> takes a long time: seems to rewrite the whole table This is not a bug.=A0 It has nothing to do with having added the column.=A0 An UPDATE statement with no WHERE clause will delete and re-add every row in the table, even if your update is setting a column to the value it already has. > I guess that adding a new column does not yet reserve space for > that new column on disk, but that the on-disk layout is only > changed as soon as I do the update (aka making the column > physically present on disk) No, the table can immediately be used, and the new column will be NULL.=A0 The UPDATE was completely unnecessary.=A0 When in doubt, use a WHERE clause that ensures you are not updating unnecessarily, like: UPDATE demo_table =A0 SET new_column =3D NULL =A0 WHERE new_column IS NOT NULL; > However from my uneducated guess (not tested) I believe that a > vacuum full followed by the update would have been much faster. It would not have been.=A0 VACUUM FULL is not often a good idea; although you are now in a state where this table is heavily bloated by the unnecessary update of every row, so it might actually be worth it now. http://rhaas.blogspot.com/2014/03/vacuum-full-doesnt-mean-vacuum-but.html -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs