pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedI'm surprised that this worked
2+ messages / 2 participants
[nested] [flat]
* I'm surprised that this worked
@ 2020-09-23 01:34 raf <raf@raf.org>
0 siblings, 1 reply; 2+ messages in thread
From: raf @ 2020-09-23 01:34 UTC (permalink / raw)
To: pgsql-general
Hi,
I just wrote a query that I didn't expect to work but I
was pleasantly surprised that it did. It looked
something like this:
select
a.aaa,
c.ccc,
d.ddd1,
d.ddd2
from
tbla a,
tblb b,
tblc c,
funcd(c.id) d
where
a.something = something and
b.something = a.something and
c.something = b.something
How does it know which c.id to use for the function
without going all cartesian product on me? Maybe it
makes no sense for such a parameterised function to be
part of a cartesian product. Actually, that function
returns a setof record but only ever a single record.
That might be relevant.
I was sure I'd done something similar once that
(sensibly) didn't work, and I needed a loop to call the
function in, but I might be thinking of something in an
outer join's "on" clause. Does that make sense?
Even more impressed with Postgresql than usual. :-)
cheers,
raf
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: I'm surprised that this worked
@ 2020-09-23 02:31 David G. Johnston <david.g.johnston@gmail.com>
parent: raf <raf@raf.org>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2020-09-23 02:31 UTC (permalink / raw)
To: raf <raf@raf.org>; +Cc: pgsql-general
On Tue, Sep 22, 2020 at 6:34 PM raf <raf@raf.org> wrote:
> Hi,
>
> I just wrote a query that I didn't expect to work but I
> was pleasantly surprised that it did. It looked
> something like this:
>
> select
> a.aaa,
> c.ccc,
> d.ddd1,
> d.ddd2
> from
> tbla a,
> tblb b,
> tblc c,
> funcd(c.id) d
> where
> a.something = something and
> b.something = a.something and
> c.something = b.something
>
> How does it know which c.id to use for the function
> without going all cartesian product on me?
Using the comma-separated from syntax doesn't force the planner to perform
a full multi-relation cartesian join (though conceptually that is what
happens) - it still only joins two relations at a time. After it joins a,
b, and c it joins each row of that result with all of the rows produced by
evaluating funcd(c.id).
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-09-23 02:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 01:34 I'm surprised that this worked raf <raf@raf.org>
2020-09-23 02:31 ` David G. Johnston <david.g.johnston@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox