Proposed patch to adjust UNION/CASE/etc type resolution rules

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-patches(at)postgreSQL(dot)org
Subject: Proposed patch to adjust UNION/CASE/etc type resolution rules
Date: 2007-11-25 01:40:45
Message-ID: 7246.1195954845@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

The attached proposed patch addresses the recent gripe that there is no
way for UNION (or related constructs) to return a domain type, because
select_common_type() always smashes all its inputs to base types:
http://archives.postgresql.org/pgsql-performance/2007-11/msg00278.php

The minimum-impact way to fix that seems to be to add an initial test to
see whether all the given types are exactly the same non-unknown type.
If so, return that; otherwise proceed with the existing algorithm. This
approach has an additional small advantage of making select_common_type()
a bit faster for trivial cases, since it can skip catalog lookups.

Note that this method will not be intelligent about cases involving
domains over domains --- you'll get the base type, even if one of the
domains is a super-domain of all the others. But it's hard to see how
to handle that efficiently, and it's not clear that there's much call
for it anyway.

The patch also removes some tests for InvalidOid, which have clearly been
dead code for quite some time now, because getBaseType() would fail on
that input.

Also, clarify the manual's not-very-precise description of the existing
algorithm's behavior.

As I mentioned earlier today, I think we should address this for 8.3,
because fooling with the resolution rules seems like something that
should only happen in major releases.

Comments?

regards, tom lane

Attachment Content-Type Size
unknown_filename text/plain 6.7 KB

Browse pgsql-patches by date

  From Date Subject
Next Message Brendan Jurd 2007-11-25 16:51:37 Empty arrays with ARRAY[]
Previous Message Bruce Momjian 2007-11-24 20:15:37 Re: Problem with pg_dump -n schemaname