Re: WIP: Join push-down for foreign tables

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: Shigeru Hanada <shigeru(dot)hanada(at)gmail(dot)com>, Kohei KaiGai <kaigai(at)kaigai(dot)gr(dot)jp>, Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: WIP: Join push-down for foreign tables
Date: 2011-12-02 16:55:12
Message-ID: 19146.1322844912@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> writes:
> Tom, what do you think of this part? I think it would be a lot more
> natural API if the planner could directly ask the FDW to construct a
> plan for a three (or more)-way join, instead of asking it to join a join
> relation into another relation.

I think this is fundamentally not going to work, at least not without
major and IMO unwise surgery on the planner. Building up joins pairwise
is what it does.

Furthermore, you seem to be imagining that there is only one best path
for any join, which isn't the case. We'll typically have several paths
under consideration because of cheapest-startup versus cheapest-total
and/or different resulting sort orders. If we do what you're
suggesting, that's going to either break entirely or require a much more
complicated API for PlanForeignJoin.

> Does the planner expect the result from the foreign server to be
> correctly sorted, if it passes pathkeys to that function?

Well, the result path should be marked with pathkeys if it is known to
be sorted a certain way, or with NIL if not. There's no prejudgment as
to what a particular join method will produce. That does raise
interesting questions though as to how to interact with the remote-end
planner --- if we've reported that a path has certain pathkeys, that
probably means that the SQL sent to the remote had better say ORDER BY,
which would be kind of annoying if in the end we weren't depending on
the path to be sorted. I'm not sure what it would take to pass that
information back down, though. What we might have to do to make this
work conveniently is generate two versions of every foreign path: one
marked with pathkeys, and one not. And make sure the former has a
somewhat-higher cost. Then we'd know from which path gets picked
whether the plan is actually depending on sorted results.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2011-12-02 18:45:16 Re: review: CHECK FUNCTION statement
Previous Message Merlin Moncure 2011-12-02 16:16:17 Re: Java LISTEN/NOTIFY client library work-around