Re: CREATE ROUTINE MAPPING

From: David Fetter <david(at)fetter(dot)org>
To: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>, Pg <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: CREATE ROUTINE MAPPING
Date: 2018-01-25 05:13:04
Message-ID: 20180125051304.GE3977@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jan 18, 2018 at 04:09:13PM -0500, Corey Huinker wrote:
> >
> >
> > >
> > > But other situations seem un-handle-able to me:
> > >
> > > SELECT remote_func1(l.x) FROM local_table l WHERE l.active = true;
> >
> > Do we have any way, or any plan to make a way, to push the set (SELECT
> > x FROM local_table WHERE active = true) to the remote side for
> > execution there? Obviously, there are foreign DBs that couldn't
> > support this, but I'm guessing they wouldn't have much by way of UDFs
> > either.
> >
>
> No. The remote query has to be generated at planning time, so it can't make
> predicates out of anything that can't be resolved into constants by the
> planner itself. The complexities of doing so would be excessive, far better
> to let the application developer split the queries up because they know
> better which parts have to resolve first.

So Corey and I, with lots of inputs from Andrew Gierth and Matheus
Oliveira, have come up with a sketch of how to do this, to wit:

- Extend CREATE FUNCTION to take either FOREIGN and SERVER or AS and
LANGUAGE as parameters, but not both. This seems simpler, at least
in a proof of concept, than creating SQL standard compliant grammar
out of whole cloth. The SQL standard grammar could be layered in
later via the rewriter if this turns out to work.

- In pg_proc, store foreign functions as having a new language,
sql_med, which doesn't actually exist. This "language" would
function as a hint to the planner.

- Add a new system catalog for foreign functions that references
pg_proc and pg_foreign_server. Writing to it would also do the usual
stuff with pg_depend.

- During planning, at least to start, we'd ensure that foreign
functions can only take arguments on the same server.

- Once it's established that the combinations could actually work,
execution gets pushed to the foreign server(s)

What say?

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2018-01-25 05:19:03 Re: Further cleanup of pg_dump/pg_restore item selection code
Previous Message Robert Haas 2018-01-25 04:39:26 Re: pgsql: Add parallel-aware hash joins.