Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 24C22650520 for ; Sun, 13 Jul 2008 22:46:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 55107-08 for ; Sun, 13 Jul 2008 22:46:44 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wdscexfe01.sc.wdc.com (wdscexfe01.sc.wdc.com [129.253.170.53]) by postgresql.org (Postfix) with ESMTP id 39EEC6500BD for ; Sun, 13 Jul 2008 22:46:50 -0300 (ADT) Received: from wdmyexbe03.my.asia.wdc.com ([129.253.105.55]) by wdscexfe01.sc.wdc.com with Microsoft SMTPSVC(6.0.3790.1830); Sun, 13 Jul 2008 18:46:20 -0700 Received: from 129.253.107.158 ([129.253.107.158]) by wdmyexbe03.my.asia.wdc.com ([129.253.105.55]) with Microsoft Exchange Server HTTP-DAV ; Mon, 14 Jul 2008 01:46:18 +0000 Received: from neuromancer by 129.253.105.55; 14 Jul 2008 09:46:46 +0800 Subject: [SOLVED] Re: Altering a column type - Most efficient way From: Ow Mun Heng To: Kevin Grittner Cc: Alvaro Herrera , Tom Lane , Pgsql performance , Mario Weilguni In-Reply-To: <48772E39.EE98.0025.0@wicourts.gov> References: <1215676380.15319.2.camel@neuromancer.home.net> <4875C9FA.7020101@sime.com> <1215682481.15319.14.camel@neuromancer.home.net> <20080710135756.GD3757@alvh.no-ip.org> <1215742620.853.10.camel@neuromancer.home.net> <20080711134423.GA4110@alvh.no-ip.org> <20080711134423.GA4110@alvh.no-ip.org> <3462.1215786454@sss.pgh.pa.us> <48772E39.EE98.0025.0@wicourts.gov> Content-Type: text/plain Content-Transfer-Encoding: 7bit Date: Mon, 14 Jul 2008 09:46:46 +0800 Message-Id: <1216000006.22806.9.camel@neuromancer.home.net> Mime-Version: 1.0 X-Mailer: Evolution 2.22.0 X-OriginalArrivalTime: 14 Jul 2008 01:46:20.0615 (UTC) FILETIME=[6A289570:01C8E553] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/119 X-Sequence-Number: 30719 On Fri, 2008-07-11 at 09:55 -0500, Kevin Grittner wrote: > > Alvaro Herrera writes: > >>> Ow Mun Heng wrote: > >>> If it were this simple a change, I'm not certain why (I believe) PG > >>>is checking each and every row to see if it will fit into the new column > >>> definition/type. > >Because the code that does the ALTER TYPE is very generic, and it > > doesn't (yet) have an optimization that tells it to skip the check > > and the possible table rewrite in the cases where it's obviously not > >needed(like this one). > If there's some low-hanging fruit here, +1 for getting that. I just tested this out and everything seems to be working fine. (cross fingers - for now and if I do report back, it means we've crashed and burned, but as of now... the low hanging fruit is tasty) This 2 sec change is much preferred over the 3+ hour per table. I agree with Tom that this is not useful in _all_ cases and may seem to look like a hack, but it really isn't. Given that the condition that we're expaning the min length rather than the opposite, it should be pretty safe. Guys(/gals) Thanks very much for brightening up a dreadry Monday morning.