Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 971EF634CB5 for ; Thu, 24 Jun 2010 12:03:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 91943-01 for ; Thu, 24 Jun 2010 15:03:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 0FD75634CB3 for ; Thu, 24 Jun 2010 12:03:38 -0300 (ADT) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id o5OF3go14004; Thu, 24 Jun 2010 11:03:42 -0400 (EDT) From: Bruce Momjian Message-Id: <201006241503.o5OF3go14004@momjian.us> Subject: Re: ALTER Table and CLUSTER does adding a new column rewrite clustered? (8.4.3) In-Reply-To: <37F2FA33-49B6-478D-BCFE-FD0DBC4CBBA8@richrelevance.com> To: Scott Carey Date: Thu, 24 Jun 2010 11:03:42 -0400 (EDT) CC: postgres performance list X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1277391822-740-2_" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/432 X-Sequence-Number: 39288 --ELM1277391822-740-2_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" Scott Carey wrote: > v. 8.4.3 > > I have a table that has several indexes, one of which the table is > clustered on. If I do an ALTER TABLE Foo ADD COLUMN bar integer not > null default -1; > > It re-writes the whole table. All good questions: > * Does it adhere to the CLUSTER property of the table and write the new > version clustered? The new table is the exact same heap ordering as the old table; it does not refresh the clustering if the table has become unclustered. > * Does it properly write it with the FILLFACTOR setting? Yes, inserts are used to populate the new table, and inserts honor FILLFACTOR. > * Are all the indexes re-created too, or are they bloated and need a REINDEX? They are recreated. > http://www.postgresql.org/docs/8.4/static/sql-altertable.html > does not seem to answer the above, it mentions the conditions that > cause a rewrite but does not say what the state is after the rewrite > with respect to CLUSTER, FILLFACTOR, and index bloat. I have added a documentation patch to mention the indexes are rebuilt; applied patch attached. The gory details can be found in src/backend/commands/tablecmds.c. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + None of us is going to be here forever. + --ELM1277391822-740-2_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/rtmp/diff" Index: doc/src/sgml/ref/alter_table.sgml =================================================================== RCS file: /cvsroot/pgsql/doc/src/sgml/ref/alter_table.sgml,v retrieving revision 1.114 diff -c -c -r1.114 alter_table.sgml *** doc/src/sgml/ref/alter_table.sgml 9 Jun 2010 17:48:10 -0000 1.114 --- doc/src/sgml/ref/alter_table.sgml 24 Jun 2010 14:54:00 -0000 *************** *** 689,696 **** Adding a column with a non-null default or changing the type of an ! existing column will require the entire table to be rewritten. This ! might take a significant amount of time for a large table; and it will temporarily require double the disk space. Adding or removing a system oid column likewise requires rewriting the entire table. --- 689,696 ---- Adding a column with a non-null default or changing the type of an ! existing column will require the entire table and indexes to be rewritten. ! This might take a significant amount of time for a large table; and it will temporarily require double the disk space. Adding or removing a system oid column likewise requires rewriting the entire table. --ELM1277391822-740-2_--