I've not read whole of the patch yet, but I have basic questions. 1) IIUC, GetForeignRelSize should set baserel->rows to the number of rows the ForeignScan node returns to upper node, but not the number of rows FDW returns to core executor, right?
BTW, once Fujita-san's ANALYZE support patch is merged, we will be able to get rows estimatation easily by calling clauselist_selectivity with baserel->tuples and baserestrictinfo. Otherwise, pgsql_fdw would still need to execute EXPLAIN on remote side to get meaningful rows estimation. 2) ISTM that pgsql_fdw needs to execute EXPLAIN on remote side for each possible remote query to get meaningful costs estimation, and it requires pgsql_fdw to generate SQL statements in GetForeignPaths. I worry that I've misunderstood intention of your design because you've mentioned postponing SQL deparsing to createplan time. I'll read the document and patch, and fix pgsql_fdw so that it can work with new API. As for now, I think that pgsqlPlanForeignScan should be separated like below: GetForeignRelSize 1) Retrieve catalog infomation via GetForeignFoo funcitons. 2) Generate simple remote query which has no WHERE clause. 3) Execute EXPLAIN of simple query, and get rows and costs estimation. 4) Set baserel->rows. All information above are stored in baserel->fdw_private to use them in subsequent GetForeignPaths. If ANALYZE of foreign tables is supported, we can postpone 2) and 3) to GetForeignPaths. GetForeignPaths 1) Repeat for each possible remote query: 1-1) Generate remote query, such as with-WHERE and with-ORDER BY. 1-2) Execute EXPLAIN of generated query, and get costs estimation (rows estimation is ignored because it's useless in planning). 1-3) Call add_path and create_foreignscan_path for the query. GetForeignPlan 1) Create fdw_exprs from baserestrictinfo, with removing clauses which are pushed down by selected path. Regards, -- Shigeru Hanada -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers