Re: FDW: ForeignPlan and parameterized paths

From: Ronan Dunklau <rdunklau(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: FDW: ForeignPlan and parameterized paths
Date: 2012-12-20 05:38:44
Message-ID: CAJWq4=Z_F-psbTz+Fn=tUYK9ZXoQYzKprZG5Xer5=Eo6u3fwLw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> I intentionally did the nestloop_params substitution after calling
> GetForeignPlan not before. It's not apparent to me why it would be
> useful to do it before, because the FDW is going to have no idea what
> those params represent. (Note that they represent values coming from
> some other, probably local, relation; not from the foreign table.)

Even if the FDW have no idea what they represent, it can identify a
clause of the form Var Operator Param, which allows to store the param
reference (paramid) for retrieving the param value at execution time.
If the chosen best path is a parameterized path that has been built by
the FDW, it allows to push down this restriction.

If this isn't possible, the only way I found to use those clauses
would be at scan time.

Lets's assume atable is a local relation, and aftable is a foreign
table, and the query looks like this:

select * from atable t1 inner join aftable t2 on t1.c1 = t2.c1

The FDW identifies the join clause on its column c1, and build a
parameterized path on this column (maybe because this column is unique
and indexed on the remote side).

The planner chooses this path, building a nested loop rescanning the
foreign table with this parameter value reflecting the outer relation
value (maybe because the local relation's size is much smaller than
the remote relation's size).

In that case, it seems to be of particular importance to have access
to the clause, so that the nested loop can work as intended: avoiding
a full seqscan on the remote side.

Or is there another way to achieve the same goal ?

Regards,

--
Ronan Dunklau

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brendan Jurd 2012-12-20 06:40:51 Re: operator dependency of commutator and negator, redux
Previous Message Groshev Andrey 2012-12-20 05:34:44 Re: [GENERAL] trouble with pg_upgrade 9.0 -> 9.1