Postgresql - FDW, ForeignScanState and subqueries

From: Ronan Dunklau <rdunklau(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Postgresql - FDW, ForeignScanState and subqueries
Date: 2011-10-20 16:28:11
Message-ID: CAJWq4=b-je5OrXw9LDua6pydBTo0G7ei=5ORmCBC-heHpxtCKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello.

Sorry if this is not the appropriate mailing list, but I understood that I
needed to post here first.

Warning: I'm not a native english speaker ;)

I'm implementing a Foreign Data Wrapper, and I'm trying to "optimize" it by
parsing the required columns and simple "quals" from the foreignscanstate.

Let's suppose I have a table defined like this:

create foreign table test (
name character varying,
value character varying,
bigcolumn bytea
)

Populated like this:

name | value | bigcolumn
----------+--------+------------------------------------------
test2 | 4 | \x72616e646f6d737472696e676f666279746573
test1 | 1 | \x72616e646f6d737472696e676f666279746573
test2 | 2 | \x72616e646f6d737472696e676f666279746573
test2 | 3 | \x72616e646f6d737472696e676f666279746573
(4 lignes)

Now, if I query my table like this (a subquery, joined on the outer query),
what info should I be able to parse from the PlanState ?

select name, (select max(value) from test t2 where t2.name = t1.name) as max
from test t1;

I don't really know much about postgresql internals, regarding execution
plans, but here is what I guessed from what I managed to extract from the
plan tree so far:

- The outer query is executed once, restricting only the needed columns
- The subquery is executed once for each row, with:
- all columns from the table are requested in a "target entry" node, even
if the query only need the name and value columns.
- the value corresponding to the name from the outer query is somehow
passed in as an Expr of type T_Param, in the quals field.

How can I retrieve the value from the Param struct ?
The source does not help me much with what to do regarding the various
fields in the struct.
Does postgresql really fetch all columns in a subselect, or am I just
parsing the tree in a wrong way ?

I've tried to look at the oracle-fdw code, but I don't understand what they
are doing with params.

Thank you !

--
Ronan Dunklau

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adam Tistler 2011-10-20 16:45:43 Re: timeline X of the primary does not match recovery target timeline Y
Previous Message Jeff Davis 2011-10-20 16:00:08 Re: timeline X of the primary does not match recovery target timeline Y