Re: join from array or cursor - Mailing list pgsql-general

From Sam Mason
Subject Re: join from array or cursor
Date
Msg-id 20090821152255.GE5407@samason.me.uk
Whole thread Raw
In response to Re: join from array or cursor  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: join from array or cursor  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Fri, Aug 21, 2009 at 10:49:52AM -0400, Merlin Moncure wrote:
> On Fri, Aug 21, 2009 at 10:17 AM, Sam Mason<sam@samason.me.uk> wrote:
> >   CREATE TYPE foo AS ( i int, j int );
> >
> >   SELECT (id((SELECT (1,2)::foo))).*;
> >
> > or am I missing something obvious?
>
> I think that what you are bumping in to is that there is no real
> definition of '*' in the query.  've griped about this a few times. If
> type 't' has fields a,b,
>
> select (t).* is expanded to select (t).a, (t).b.

OK, but that's not because of there being no "real definition" of *.
It seems perfectly well defined in the example above as a tuple of two
integers.  The thing that causes it to go wrong here is that PG doesn't
know that doing this expansion (as you noted above) can cause the query
to become very expensive.  PG should instead arrange that the expression
"t" is run exactly once and reuse the single result for all columns.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: David Waller
Date:
Subject: "Number of columns exceed limit" on a hierarchy of views
Next
From: "Chris Hopkins"
Date:
Subject: Re: Out of memory on pg_dump