Re: ALTER TYPE 3: add facility to identify further no-work cases - Mailing list pgsql-hackers

From Noah Misch
Subject Re: ALTER TYPE 3: add facility to identify further no-work cases
Date
Msg-id 20110127002457.GC2498@tornado.leadboat.com
Whole thread Raw
In response to Re: ALTER TYPE 3: add facility to identify further no-work cases  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ALTER TYPE 3: add facility to identify further no-work cases  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: ALTER TYPE 3: add facility to identify further no-work cases  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wed, Jan 26, 2011 at 06:29:57PM -0500, Tom Lane wrote:
> Noah Misch <noah@leadboat.com> writes:
> > If we hook this into eval_const_expressions, it definitely seems
> > cleaner to attach the auxiliary function to the pg_proc.  Otherwise,
> > we'd reconstruct which cast led to each function call -- is there even
> > enough information available to do so unambiguously?
> 
> As far as that goes, yes there is --- otherwise ruleutils would be
> unable to reverse-list cast constructs.  IIRC the function call is
> marked as being a cast, and you get the source and dest type IDs
> from ordinary exprType() inspection.

Good point.  So it is, FuncExpr.funcformat conveys that.

> > For the syntax, then, would a new common_func_opt_item of "WHEN func" fit?
> 
> WHEN is appropriate for the restricted CAST case, but it doesn't seem
> like le mot juste for a general function option, unless we restrict
> the helper function to return boolean which is not what I had in mind.

True.  Uhh, "PARSER MAPPING func"?  "PLANS CONVERSION func"?

> > That covers fully-removable casts, but ALTER TABLE still needs to identify casts
> > that may throw errors but never change the value's binary representation.
> 
> I remain completely unexcited about optimizing that case, especially if
> it doesn't fit into a general framework.  The bang for the buck ratio
> is not good: too much work, too much uglification, too little return.

The return looks attractive when you actually save six hours of downtime.  If
I'm the only one that sees such a savings for one of his databases, though, I
suppose it's not worthwhile.  We'd miss optimizing these cases:

numeric(8,2) -> numeric(7,2)
varbit(8) -> varbit(7)
text -> xml

The xml one is the most interesting to me.  In the design thread, Robert also
expressed interest in that one.  Jim Nasby mentioned numeric generally; Jim,
what kind of numeric conversions are important to you?  If anyone else will miss
one of those greatly, please speak up.

I found that many interesting cases in this area, most notably varchar(8) ->
varchar(4), are safe a good deal of the time, but not provably so.  So perhaps a
system for automatically detecting them would be overkill, but an addition to
the ALTER TABLE syntax[1] to request them would be worthwhile.

nm

[1] http://archives.postgresql.org/message-id/20110106042626.GA28230@tornado.leadboat.com


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: new compiler warnings
Next
From: Tom Lane
Date:
Subject: Re: ALTER TYPE 3: add facility to identify further no-work cases