pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <kgrittn@ymail.com>
To: eike@inter.net <eike@inter.net>
To: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: BUG #10591: setting newly added columns to null is slow
Date: Tue, 10 Jun 2014 13:15:47 -0700 (PDT)
Message-ID: <1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com> (raw)
In-Reply-To: <20140610183719.2589.93121@wrigleys.postgresql.org>
References: <20140610183719.2589.93121@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"eike@inter.net" <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=null; (quite slow)
>-> takes a long time: seems to rewrite the whole table

This is not a bug.  It has nothing to do with having added the
column.  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.  The UPDATE was completely unnecessary.  When in doubt, use a
WHERE clause that ensures you are not updating unnecessarily, like:

UPDATE demo_table
  SET new_column = NULL
  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.  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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com>
Permalink:  ../1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com/
Also on:    postgresql.org/message-id/1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kgrittn@ymail.com, eike@inter.net
  Subject: Re: BUG #10591: setting newly added columns to null is slow
  In-Reply-To: <1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com>
  References: <20140610183719.2589.93121@wrigleys.postgresql.org> <1402431347.74639.YahooMailNeo@web122305.mail.ne1.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox