Re: ALTER TYPE 3: add facility to identify further no-work cases

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Noah Misch <noah(at)leadboat(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: ALTER TYPE 3: add facility to identify further no-work cases
Date: 2011-01-26 22:12:00
Message-ID: AANLkTin0JNVtTnRgWJ1WP7CCwgzVP=d8nUr071p0s9kY@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 26, 2011 at 5:01 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Wed, Jan 26, 2011 at 4:02 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> I don't mind confining the feature to casts to start with, but it might
>>> be a good idea to specify the check-function API in a way that would let
>>> it be plugged into a more generally available call-simplification hook
>>> later.
>
>> Got any suggestions?  My thought was that it should just get (type,
>> typemod, type, typemod) and return a boolean.  We could do something
>> more complicated, like Expr -> Expr, but I'm pretty unconvinced
>> there's any value there.
>
> Well, (type, typemod, type, typemod) would be fine as long as the only
> case you're interested in optimizing is typemod-lengthening coercions.
> I think we're going to want the more general Expr-to-Expr capability
> eventually.
>
> I guess we could do the restricted case for now, with the idea that
> there could be a standard Expr-to-Expr interface function created later
> and installed into the generic hook facility for functions that are cast
> functions.  That could look into pg_cast and make the more restricted
> call when appropriate.  (The meat of this function would be the same
> code you'd have to add to eval_const_expressions anyway for the
> hard-wired version...)

Well, if you're positive we're eventually going to want this in
pg_proc, we may as well add it now. But I'm not too convinced it's
the right general API. The number of people writing exactly x + 0 or
x * 0 in a query has got to be vanishingly small; I'm not eager to add
additional parse analysis time to every SQL statement that has a
function in it just to detect those cases. Even slightly more
complicated problems seem intractable - e.g. (x + 1) = x can be
simplified to constant false, and NOT ((x + 1) = x) can be simplified
to x IS NOT NULL, but under the proposed API those would have to hang
off of =(int4,int4), which seems pretty darn ugly.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-01-26 22:15:54 Re: new compiler warnings
Previous Message Tom Lane 2011-01-26 22:04:59 Re: [COMMITTERS] pgsql: Remove arbitrary ALTER TABLE .. ADD COLUMN restriction.