Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A7AF264FCE7 for ; Fri, 11 Jul 2008 11:27:42 -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 24182-03 for ; Fri, 11 Jul 2008 11:27:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 66FAF650315 for ; Fri, 11 Jul 2008 11:27:36 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m6BERYAZ003463; Fri, 11 Jul 2008 10:27:34 -0400 (EDT) To: Alvaro Herrera cc: Ow Mun Heng , Mario Weilguni , Pgsql performance Subject: Re: Altering a column type - Most efficient way In-reply-to: <20080711134423.GA4110@alvh.no-ip.org> 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> Comments: In-reply-to Alvaro Herrera message dated "Fri, 11 Jul 2008 09:44:23 -0400" Date: Fri, 11 Jul 2008 10:27:34 -0400 Message-ID: <3462.1215786454@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/100 X-Sequence-Number: 30700 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). Awhile back I looked into teaching ALTER TYPE that it needn't rewrite if the type conversion expression parses out as just a Var with RelabelType, but it seemed that that wouldn't cover very much of the use-cases where a human thinks that it's "obvious" that no rewrite is needed. You'd really need to build in hard-wired knowledge about the behavior of specific coercion functions, which seems entirely unappealing. regards, tom lane