Re: DOMAINs and CASTs - Mailing list pgsql-hackers

From Jaime Casanova
Subject Re: DOMAINs and CASTs
Date
Msg-id BANLkTik+Tbka8jM2O1PLP9QDPEjaCSiajw@mail.gmail.com
Whole thread Raw
In response to Re: DOMAINs and CASTs  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: DOMAINs and CASTs  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On Sun, May 15, 2011 at 1:53 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>
> So let's think about some harder scenarios.
>
> Given two types T1 and T2, and two domains D1 over T1 and D2 over T2,
> and a cast from a value of type D1 to type D2, then:
>

ok. a few fair questions, thanks

> (1) If there is an implicit cast from D1 to D2 and an implicit cast
> from T1 to T2, then presumably we should use the cast from D1 to D2,
> since it's more specific.  Or if none of the available casts involve
> domains, but there is a cast of some sort from T1 to T2, then it seems
> clear to use that one.  But what if we instead have a cast from D1 to
> T2 and a cast from T1 to D2?  Which one should we prefer?  Why?
>

ok, this is the specific problem i said not to touch in my patch...
but, IMHO, we should use T1->D2 on the base that that is the final
type the user wants...

> (2) What happens if there are casts T1 -> T2 and D1 -> D2, but the D1
> -> D2 cast is explicit, while the T1 -> T2 cast is on-assignment?
> Should we use the D1->D2 cast when the context is explicit and the
> T1->T2 when the context is on-assignment?  That seems confusing.
> Alternatively, we could decide that the on-assignment cast always
> beats the explicit cast, even in an explicit-cast context.  But that
> amounts to ignoring the D1->D2 cast altogether - is that what we want?
>

confusing yes. still, imho, we should use the casts based on context
as we always do...

> (3) What happens if one or both of T1 or T2 are themselves domains
> over some other types T3 and T4, respectively?  Now there are nine
> possible pairings of types (any of D1, T1, T3 with any of D2, T2, T4)
> and in each case the available cast could have one of three contexts.
> How do we decide which cast wins?  Also, we might now need 9 probes
> into pg_cast to find all the relevant casts, whereas the current code
> needs just one - even in the previous scenario, we might need 4 probes
> instead of one.  That'll be slower - is it worth it?  What's the
> performance penalty in an artificially constructed worst case?
>
> (4) What happens if T1 is a domain over T2?  Then we have another
> option - cast D1 to D2 by smashing it to its base type twice (first to
> T1, then to T2), and the re-applying any domain constraint on D2.  Is
> that preferable to applying a cast from D1 to T1 and then casting to
> D2?  Is it preferable to applying a cast from D1 to T2 and then
> re-applying the domain constraint on D2?  Is it preferable to a cast
> directly from D1 to D2?  And in each case, does the context of the
> cast matter?
>

these two are very good questions and i can't see a "right" answer for them

> I'm not throwing these questions out to be flip or to make life
> difficult - I'm just saying they need to be thought about, and the
> answers don't seem obvious (to me).
>

still, we have a problem... because we are happily ignoring correctely
created casts...
at least, we should document that casts on domains are ignored and
that we should use the base types instead, maybe even a warning or a
notice when issuing the CREATE CAST command using domains...

make the user think everything is fine when it's not is not a good idea

--
Jaime Casanova         www.2ndQuadrant.com
Professional PostgreSQL: Soporte y capacitación de PostgreSQL


pgsql-hackers by date:

Previous
From: Jaime Casanova
Date:
Subject: Re: adding a new column in IDENTIFY_SYSTEM
Next
From: Robert Haas
Date:
Subject: Re: DOMAINs and CASTs