Re: pgsql_fdw, FDW for PostgreSQL server
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Shigeru Hanada <shigeru.hanada@gmail.com>
Cc: Albe Laurenz <laurenz.albe@wien.gv.at>, Kevin Grittner <Kevin.Grittner@wicourts.gov>, Robert Haas <robertmhaas@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>, Kohei KaiGai <kaigai@kaigai.gr.jp>, Martijn van Oosterhout <kleptog@svana.org>, Etsuro Fujita <fujita.etsuro@lab.ntt.co.jp>, Hitoshi Harada <umi.tanuki@gmail.com>
Date: 2012-03-09T05:00:01Z
Lists: pgsql-hackers
Attachments
- fdw-plan-api-rewrite.patch (text/x-patch) patch
I wrote: > There are a couple of other points that make me think we need to revisit > the PlanForeignScan API definition some more, too. ... > So we need to break down what PlanForeignScan currently does into three > separate steps. The first idea that comes to mind is to call them > GetForeignRelSize, GetForeignPaths, GetForeignPlan; but maybe somebody > has a better idea for names? Attached is a draft patch for that. While I was working on this I realized that we were very far short of allowing FDWs to set up expressions of their choice for execution; there was nothing for that in setrefs.c, nor some other places that need to post-process expressions. I had originally supposed that fdw_private could just contain some expression trees, but that wasn't going to work without post-processing. So this patch attempts to cover that too, by breaking what had been fdw_private into a "private" part and an "fdw_exprs" list that will be subject to expression post-processing. (The alternative to this would be to do post-processing on all of fdw_private, but that would considerably restrict what can be in fdw_private, so it seemed better to decree two separate fields.) Working on this also helped me identify some other things that had been subliminally bothering me about pgsql_fdw's qual pushdown code. That patch is set up with the idea of pushing entire quals (boolean RestrictInfo expressions) across to the remote side, but I think that is probably the wrong granularity, or at least not the only mechanism we should have. IMO it is more important to provide a structure similar to index quals; that is, what you want to identify is RestrictInfo expressions of the form remote_variable operator local_expression where the operator has to be one that the remote can execute with the same semantics as we think it has, but the only real restriction on the local_expression is that it be stable, because we'll execute it locally and send only its result value across to the remote. (The SQL sent to the remote looks like "remote_variable operator $1", or some such.) Thus, to take an example that's said to be unsafe in the existing code comments, there's no problem at all with remote_timestamp_col = now() as long as we execute now() locally. There might be some value in pushing entire quals across too, for clauses like "remote_variable_1 = remote_variable_2", but I believe that these are not nearly as important as "variable = constant" and "variable = join_variable" cases. Consider that when dealing with a local table, only the latter two cases can be accelerated by indexes. regards, tom lane