Postgresql - FDW, ForeignScanState and subqueries - Mailing list pgsql-general

From Ronan Dunklau
Subject Postgresql - FDW, ForeignScanState and subqueries
Date
Msg-id CAJWq4=b-je5OrXw9LDua6pydBTo0G7ei=5ORmCBC-heHpxtCKA@mail.gmail.com
Whole thread Raw
Responses Re: Postgresql - FDW, ForeignScanState and subqueries  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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






pgsql-general by date:

Previous
From: Jeff Davis
Date:
Subject: Re: timeline X of the primary does not match recovery target timeline Y
Next
From: Adam Tistler
Date:
Subject: Re: timeline X of the primary does not match recovery target timeline Y