Re: Function scan FDW pushdown
Álvaro Herrera писал(а) 2025-08-05 22:55:
Hello,
On 2024-Nov-05, g.kashkin@postgrespro.ru wrote:
This is a long-overdue follow-up to the original patch.
Note that this patch contains only the changes required for
function scan pushdown, examples and code related to asymmetric
join are dropped.I've marked this as returned with feedback, as several months have
passed without a further version; the current one has a number of
gotchas, including some problematic coding detected by a compiler
warning, as well as unfinished design:The issue with setting newrte->functions to NIL still persists.
[...]
I am aware that the rte->functions will now be copied even on
instances that don't utilize a FDW, but I don't see a way to solve it.
Any suggestions are welcome.Feel free to reopen this CF entry[1] once you're able to figure this
out.
Hi.
I've updated patch with latest fixes, including more checks for corner
cases.
Now function pushdown is forbidden for functions, returning sets of
complex types
or which arguments contain parameters. Together with Gleb Kashkin we've
also moved
information about functions to foreign scan private data. The tricky
part here was
to get correct rti mappings after setrefs, but it seems we've managed to
do it.
Also I've removed some changes, which are required only in presence of
asymmetric
join.
Of course, I'm targeting PostgreSQL 20.
--
Best regards,
Alexander Pyhalov,
Postgres Professional
Attachments:
v2-0001-Push-join-with-function-scan-to-remote-server.patchtext/x-diff; name=v2-0001-Push-join-with-function-scan-to-remote-server.patchDownload+1348-105
Import Notes
Reply to msg id not found: 202508051955.sao7ucalcce7@alvherre.pgsqlReference msg id not found: 202508051955.sao7ucalcce7@alvherre.pgsql
Alexander Pyhalov писал(а) 2026-03-18 15:08:
Álvaro Herrera писал(а) 2025-08-05 22:55:
Hello,
On 2024-Nov-05, g.kashkin@postgrespro.ru wrote:
This is a long-overdue follow-up to the original patch.
Note that this patch contains only the changes required for
function scan pushdown, examples and code related to asymmetric
join are dropped.I've marked this as returned with feedback, as several months have
passed without a further version; the current one has a number of
gotchas, including some problematic coding detected by a compiler
warning, as well as unfinished design:The issue with setting newrte->functions to NIL still persists.
[...]
I am aware that the rte->functions will now be copied even on
instances that don't utilize a FDW, but I don't see a way to solve
it.
Any suggestions are welcome.Feel free to reopen this CF entry[1] once you're able to figure this
out.Hi.
I've updated patch with latest fixes, including more checks for corner
cases.
Now function pushdown is forbidden for functions, returning sets of
complex types
or which arguments contain parameters. Together with Gleb Kashkin we've
also moved
information about functions to foreign scan private data. The tricky
part here was
to get correct rti mappings after setrefs, but it seems we've managed
to do it.
Also I've removed some changes, which are required only in presence of
asymmetric
join.Of course, I'm targeting PostgreSQL 20.
Hi. Updated patch to apply cleanly after recent changes.
--
Best regards,
Alexander Pyhalov,
Postgres Professional
Attachments:
v3-0001-Push-join-with-function-scan-to-remote-server.patchtext/x-diff; name=v3-0001-Push-join-with-function-scan-to-remote-server.patchDownload+1348-105
Hi,
I tested the v3 patch on current master using a postgres_fdw loopback setup.
The patch mostly applied cleanly for me, with only a small manual
conflict resolution needed in postgres_fdw.c (missing
optimizer/clauses.h include). PostgreSQL built and started
successfully after that.
For testing, I used queries involving generate_series() together with
a foreign table, for example:
SELECT *
FROM ft
JOIN generate_series(1,3) g
ON ft.id = g;
I also tried:
1. implicit join syntax
2. LATERAL usage
3. disabling hashjoin/mergejoin to force different join paths
In all cases, the plans still showed a local Function Scan and local
join execution. The Remote SQL remained:
SELECT id FROM public.localtab
So I wasn't able to observe function scan pushdown with these testcases.
Maybe I'm missing a query shape or planner condition required to
trigger the new functionality. It would help to know which cases are
currently expected to be pushed down.
Regards,
Solaimurugan V
solaimurugan vellaipandiyan писал(а) 2026-05-08 08:17:
Hi,
I tested the v3 patch on current master using a postgres_fdw loopback
setup.The patch mostly applied cleanly for me, with only a small manual
conflict resolution needed in postgres_fdw.c (missing
optimizer/clauses.h include). PostgreSQL built and started
successfully after that.For testing, I used queries involving generate_series() together with
a foreign table, for example:SELECT *
FROM ft
JOIN generate_series(1,3) g
ON ft.id = g;I also tried:
1. implicit join syntax
2. LATERAL usage
3. disabling hashjoin/mergejoin to force different join pathsIn all cases, the plans still showed a local Function Scan and local
join execution. The Remote SQL remained:
SELECT id FROM public.localtab
So I wasn't able to observe function scan pushdown with these
testcases.
Maybe I'm missing a query shape or planner condition required to
trigger the new functionality. It would help to know which cases are
currently expected to be pushed down.Regards,
Solaimurugan V
Hi. Of course, this depends on foreign scan cost. Foreign join should be
cheaper than local one.
The cost of foreign join consists from
1) cost of evaluating inner and outer part of the join,
2) total costs of retreiving rows (nrows * cost of qual evaluation),
3) cost of preparing to evaluate quals (remote and local),
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.
Look at estimate_path_cost_size().
The cost of retreiving foreign rows consists from
1) cost of estimating baserestrictinfos
2) cost of remote sequential scan
3) cost of evaluating foreign relation target list
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.
If we compare function scan pushdown for foreign table and function with
foreign join pushdown of two foreign tables, we don't have two
penalties from fdw_startup_cost here. So, for function scan pushdown to
be chosen, it should filter out significant part of data, as data
transfer cost likely dominates in foreign scan costs estimation. You can
see this on the following toy example.
CREATE EXTENSION postgres_fdw;
SELECT current_database() AS current_database,
current_setting('port') AS current_port \gset
CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (dbname :'current_database', port :'current_port');
CREATE USER MAPPING FOR current_user SERVER loopback;
CREATE table t1 (i int, j text);
create foreign table ft1 (i int, j text) server loopback options
(table_name 't1');
-- No adequate data about relation, we assume 1000+ rows in table, so
foreign join is chosen.
# explain select * from ft1 , generate_series(1,10) g where i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..172.16 rows=68 width=40)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)
-- We have actual data, there's no use to push down foreign join
postgres=# analyze ft1;
ANALYZE
postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
-----------------------------------------------------------------------------
Hash Join (cost=100.02..100.16 rows=1 width=40)
Hash Cond: (g.g = ft1.i)
-> Function Scan on generate_series g (cost=0.00..0.10 rows=10
width=4)
-> Hash (cost=100.00..100.00 rows=1 width=36)
-> Foreign Scan on ft1 (cost=100.00..100.00 rows=1 width=36)
-- If we had two foreign scans below join here, its startup cost would
be more than 2*100.
-- But evaluating function locally saves us from such great penalty.
-- Let's add some actual data.
postgres=# insert into ft1 select i, 'test'||i from
generate_series(1,1000) i;
INSERT 0 1000
postgres=# analyze ft1;
ANALYZE
-- Now we have actual data, transfering 1000 rows (plain foreign scan
costs ~ 410) and joining locally is more expensive than doing
-- remote join and transfering 10 rows.
postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..143.20 rows=10 width=15)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)
--
Best regards,
Alexander Pyhalov,
Postgres Professional
Hi!
On Fri, May 8, 2026 at 9:03 AM Alexander Pyhalov
<a.pyhalov@postgrespro.ru> wrote:
solaimurugan vellaipandiyan писал(а) 2026-05-08 08:17:
Hi,
I tested the v3 patch on current master using a postgres_fdw loopback
setup.The patch mostly applied cleanly for me, with only a small manual
conflict resolution needed in postgres_fdw.c (missing
optimizer/clauses.h include). PostgreSQL built and started
successfully after that.For testing, I used queries involving generate_series() together with
a foreign table, for example:SELECT *
FROM ft
JOIN generate_series(1,3) g
ON ft.id = g;I also tried:
1. implicit join syntax
2. LATERAL usage
3. disabling hashjoin/mergejoin to force different join pathsIn all cases, the plans still showed a local Function Scan and local
join execution. The Remote SQL remained:
SELECT id FROM public.localtab
So I wasn't able to observe function scan pushdown with these
testcases.
Maybe I'm missing a query shape or planner condition required to
trigger the new functionality. It would help to know which cases are
currently expected to be pushed down.Regards,
Solaimurugan VHi. Of course, this depends on foreign scan cost. Foreign join should be
cheaper than local one.
The cost of foreign join consists from
1) cost of evaluating inner and outer part of the join,
2) total costs of retreiving rows (nrows * cost of qual evaluation),
3) cost of preparing to evaluate quals (remote and local),
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.
Look at estimate_path_cost_size().The cost of retreiving foreign rows consists from
1) cost of estimating baserestrictinfos
2) cost of remote sequential scan
3) cost of evaluating foreign relation target list
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.If we compare function scan pushdown for foreign table and function with
foreign join pushdown of two foreign tables, we don't have two
penalties from fdw_startup_cost here. So, for function scan pushdown to
be chosen, it should filter out significant part of data, as data
transfer cost likely dominates in foreign scan costs estimation. You can
see this on the following toy example.CREATE EXTENSION postgres_fdw;
SELECT current_database() AS current_database,
current_setting('port') AS current_port \gset
CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (dbname :'current_database', port :'current_port');
CREATE USER MAPPING FOR current_user SERVER loopback;
CREATE table t1 (i int, j text);
create foreign table ft1 (i int, j text) server loopback options
(table_name 't1');-- No adequate data about relation, we assume 1000+ rows in table, so
foreign join is chosen.# explain select * from ft1 , generate_series(1,10) g where i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..172.16 rows=68 width=40)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)-- We have actual data, there's no use to push down foreign join
postgres=# analyze ft1;
ANALYZE
postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
-----------------------------------------------------------------------------
Hash Join (cost=100.02..100.16 rows=1 width=40)
Hash Cond: (g.g = ft1.i)
-> Function Scan on generate_series g (cost=0.00..0.10 rows=10
width=4)
-> Hash (cost=100.00..100.00 rows=1 width=36)
-> Foreign Scan on ft1 (cost=100.00..100.00 rows=1 width=36)-- If we had two foreign scans below join here, its startup cost would
be more than 2*100.
-- But evaluating function locally saves us from such great penalty.
-- Let's add some actual data.postgres=# insert into ft1 select i, 'test'||i from
generate_series(1,1000) i;
INSERT 0 1000
postgres=# analyze ft1;
ANALYZE-- Now we have actual data, transfering 1000 rows (plain foreign scan
costs ~ 410) and joining locally is more expensive than doing
-- remote join and transfering 10 rows.postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..143.20 rows=10 width=15)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)
Thank you for your work on improving this matter. I've updated the
patch attempting to address major concerns raised in this thread.
1) Limit the support of the pushdown with immutable functions. This
must eliminate the risk of different evaluation results on different
servers (as long as immutable is set correctly).
2) Store pointer to stub fpinfo for the function in the absorbing
foreign table. Thus, if there are multiple foreign tables, which
could absorb the function, both ways can be considered. This is
illustrated in the regression tests: the decision on which foreign
table would absorb the function can be changed depending on clause
selectivity.
------
Regards,
Alexander Korotkov
Supabase
Attachments:
v4-0001-postgres_fdw-push-down-FUNCTION-RTE-into-foreign-.patchapplication/octet-stream; name=v4-0001-postgres_fdw-push-down-FUNCTION-RTE-into-foreign-.patchDownload+462-11
Hi,
Thanks for the detailed explanation and the example queries. That
helped me better understand the costing behavior behind the pushdown
decisions.
I tested the new v4 patch on current master using a postgres_fdw
loopback setup with local table t1 and foreign table ft1.
Here’s what I observed:
- Before ANALYZE, the planner chose a local Hash Join with separate
Foreign Scan and Function Scan nodes.
- After running ANALYZE on the empty table, it still preferred local
execution, which makes sense based on the costing explanation.
- I then inserted 1000 rows into t1, ran ANALYZE again, and repeated the test.
Even after that, I still got a local Hash Join plan like:
Hash Join
- Foreign Scan on ft1
- Function Scan on generate_series
I wasn’t able to observe the pushed-down Foreign Scan plan shown in
the example from the thread.
The patch itself applied and built successfully on my side, so this
may just be due to planner cost differences or environment-specific
behavior on current master.
Regards,
Solaimurugan V
On Mon, May 11, 2026 at 9:01 AM solaimurugan vellaipandiyan <
drsolaimurugan.v@gmail.com> wrote:
Thanks for the detailed explanation and the example queries. That
helped me better understand the costing behavior behind the pushdown
decisions.I tested the new v4 patch on current master using a postgres_fdw
loopback setup with local table t1 and foreign table ft1.Here’s what I observed:
- Before ANALYZE, the planner chose a local Hash Join with separate
Foreign Scan and Function Scan nodes.
- After running ANALYZE on the empty table, it still preferred local
execution, which makes sense based on the costing explanation.
- I then inserted 1000 rows into t1, ran ANALYZE again, and repeated the
test.
Even after that, I still got a local Hash Join plan like:
Hash Join
- Foreign Scan on ft1
- Function Scan on generate_series
I wasn’t able to observe the pushed-down Foreign Scan plan shown in
the example from the thread.The patch itself applied and built successfully on my side, so this
may just be due to planner cost differences or environment-specific
behavior on current master.
This also comes from the cost model. Check this example.
# CREATE TABLE t1 (id int);
# INSERT INTO t1 SELECT g FROM generate_series(1, 1000) g;
# CREATE FOREIGN TABLE ft1 (id int) SERVER loopback OPTIONS (table_name
't1');
# ANALYZE t1;
# ANALYZE ft1;
By default the local join is selected.
# EXPLAIN (VERBOSE, COSTS ON)
SELECT * FROM ft1, generate_series(1, 100) AS g(id)
WHERE ft1.id = g.id;
QUERY PLAN
-----------------------------------------------------------------------------------------------
Hash Join (cost=102.25..332.00 rows=100 width=8)
Output: ft1.id, g.id
Hash Cond: (ft1.id = g.id)
-> Foreign Scan on public.ft1 (cost=100.00..325.00 rows=1000 width=4)
Output: ft1.id
Remote SQL: SELECT id FROM public.t1
-> Hash (cost=1.00..1.00 rows=100 width=4)
Output: g.id
-> Function Scan on pg_catalog.generate_series g
(cost=0.00..1.00 rows=100 width=4)
Output: g.id
Function Call: generate_series(1, 100)
(11 rows)
However, we can force remote join using enable_* options. You can see it
has higher cost. This is because estimate_path_cost_size() expects join
operator to be applied to the whole cross-product.
# SET enable_hashjoin = off;
# SET enable_mergejoin = off;
# SET enable_nestloop = off;
# EXPLAIN (VERBOSE, COSTS ON)
SELECT * FROM ft1, generate_series(1, 100) AS g(id)
WHERE ft1.id = g.id;
QUERY PLAN
-----------------------------------------------------------------------------------------------
Hash Join (cost=102.25..332.00 rows=100 width=8)
Output: ft1.id, g.id
Hash Cond: (ft1.id = g.id)
-> Foreign Scan on public.ft1 (cost=100.00..325.00 rows=1000 width=4)
Output: ft1.id
Remote SQL: SELECT id FROM public.t1
-> Hash (cost=1.00..1.00 rows=100 width=4)
Output: g.id
-> Function Scan on pg_catalog.generate_series g
(cost=0.00..1.00 rows=100 width=4)
Output: g.id
Function Call: generate_series(1, 100)
(11 rows)
# RESET enable_hashjoin;
# RESET enable_mergejoin;
# RESET enable_nestloop;
Also, this can be fixed using remote estimate. You also can check that v3
regression tests by Pyhalov use this approach as well.
# ALTER FOREIGN TABLE ft1 OPTIONS (ADD use_remote_estimate 'true');
# EXPLAIN (VERBOSE, COSTS ON)
SELECT * FROM ft1, generate_series(1, 100) AS g(id)
WHERE ft1.id = g.id;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
Foreign Scan (cost=102.25..143.00 rows=100 width=8)
Output: ft1.id, g.id
Relations: (public.ft1) INNER JOIN (Function g)
Remote SQL: SELECT r1.id, f2.c1 FROM (public.t1 r1 INNER JOIN
generate_series(1, 100) f2(c1) ON (((r1.id = f2.c1))))
(4 rows)
Thus, I don't see it to be a problem of this specific patch. I think this
is general inaccuracy of postgres_fdw cost model.
------
Regards,
Alexander Korotkov
Supabase
Alexander Korotkov писал(а) 2026-05-11 01:22:
Hi!
On Fri, May 8, 2026 at 9:03 AM Alexander Pyhalov
<a.pyhalov@postgrespro.ru> wrote:solaimurugan vellaipandiyan писал(а) 2026-05-08 08:17:
Hi,
I tested the v3 patch on current master using a postgres_fdw loopback
setup.The patch mostly applied cleanly for me, with only a small manual
conflict resolution needed in postgres_fdw.c (missing
optimizer/clauses.h include). PostgreSQL built and started
successfully after that.For testing, I used queries involving generate_series() together with
a foreign table, for example:SELECT *
FROM ft
JOIN generate_series(1,3) g
ON ft.id = g;I also tried:
1. implicit join syntax
2. LATERAL usage
3. disabling hashjoin/mergejoin to force different join pathsIn all cases, the plans still showed a local Function Scan and local
join execution. The Remote SQL remained:
SELECT id FROM public.localtab
So I wasn't able to observe function scan pushdown with these
testcases.
Maybe I'm missing a query shape or planner condition required to
trigger the new functionality. It would help to know which cases are
currently expected to be pushed down.Regards,
Solaimurugan VHi. Of course, this depends on foreign scan cost. Foreign join should
be
cheaper than local one.
The cost of foreign join consists from
1) cost of evaluating inner and outer part of the join,
2) total costs of retreiving rows (nrows * cost of qual evaluation),
3) cost of preparing to evaluate quals (remote and local),
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.
Look at estimate_path_cost_size().The cost of retreiving foreign rows consists from
1) cost of estimating baserestrictinfos
2) cost of remote sequential scan
3) cost of evaluating foreign relation target list
4) fdw_startup_cost
5) (fdw_tuple_cost + cpu_tuple_cost) * retrieved_rows.If we compare function scan pushdown for foreign table and function
with
foreign join pushdown of two foreign tables, we don't have two
penalties from fdw_startup_cost here. So, for function scan pushdown
to
be chosen, it should filter out significant part of data, as data
transfer cost likely dominates in foreign scan costs estimation. You
can
see this on the following toy example.CREATE EXTENSION postgres_fdw;
SELECT current_database() AS current_database,
current_setting('port') AS current_port \gset
CREATE SERVER loopback FOREIGN DATA WRAPPER postgres_fdw
OPTIONS (dbname :'current_database', port :'current_port');
CREATE USER MAPPING FOR current_user SERVER loopback;
CREATE table t1 (i int, j text);
create foreign table ft1 (i int, j text) server loopback options
(table_name 't1');-- No adequate data about relation, we assume 1000+ rows in table, so
foreign join is chosen.# explain select * from ft1 , generate_series(1,10) g where i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..172.16 rows=68 width=40)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)-- We have actual data, there's no use to push down foreign join
postgres=# analyze ft1;
ANALYZE
postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
-----------------------------------------------------------------------------
Hash Join (cost=100.02..100.16 rows=1 width=40)
Hash Cond: (g.g = ft1.i)
-> Function Scan on generate_series g (cost=0.00..0.10 rows=10
width=4)
-> Hash (cost=100.00..100.00 rows=1 width=36)
-> Foreign Scan on ft1 (cost=100.00..100.00 rows=1
width=36)-- If we had two foreign scans below join here, its startup cost would
be more than 2*100.
-- But evaluating function locally saves us from such great penalty.
-- Let's add some actual data.postgres=# insert into ft1 select i, 'test'||i from
generate_series(1,1000) i;
INSERT 0 1000
postgres=# analyze ft1;
ANALYZE-- Now we have actual data, transfering 1000 rows (plain foreign scan
costs ~ 410) and joining locally is more expensive than doing
-- remote join and transfering 10 rows.postgres=# explain select * from ft1 , generate_series(1,10) g where
i=g;
QUERY PLAN
------------------------------------------------------
Foreign Scan (cost=100.00..143.20 rows=10 width=15)
Relations: (ft1) INNER JOIN (generate_series() g)
(2 rows)Thank you for your work on improving this matter. I've updated the
patch attempting to address major concerns raised in this thread.1) Limit the support of the pushdown with immutable functions. This
must eliminate the risk of different evaluation results on different
servers (as long as immutable is set correctly).
2) Store pointer to stub fpinfo for the function in the absorbing
foreign table. Thus, if there are multiple foreign tables, which
could absorb the function, both ways can be considered. This is
illustrated in the regression tests: the decision on which foreign
table would absorb the function can be changed depending on clause
selectivity.------
Regards,
Alexander Korotkov
Supabase
Hi.
I've tested updated patch a bit.
1) deparseColumnRef() doesn't account for whole row vars.
In queries like
UPDATE remote_tbl r SET b=5 FROM UNNEST(array[box '((2,3),(-2,-3))']) AS
t (bx) WHERE r.a = area(t.bx)
it fails with assert that varattno should be > 0. When we lock
non-relation RTE, we select whole row var, and we have to deparse it for
function RTE.
You've removed check for function return type. This seems to be
dangerous. Old example
CREATE OR REPLACE FUNCTION f_ret_record() RETURNS record AS $$ SELECT
(1,2)::record $$ language SQL IMMUTABLE;
ALTER EXTENSION postgres_fdw ADD function f_ret_record();
EXPLAIN (VERBOSE, COSTS OFF)
SELECT s FROM remote_tbl rt, f_ret_record() AS s(a int, b int)
WHERE s.a = rt.a;
fails with
ERROR: a column definition list is required for functions returning
"record"
2) postgresBeginForeignScan() can step on function RTE, and doesn't know
what to do with it:
SELECT * FROM unnest(array[2,3,4]) n, remote_tbl r WHERE r.a = n;
ERROR: cache lookup failed for foreign table 0
So, we need to look for the first RTE_RELATION, as in older patch
version.
3) A lot of complexity in the old patch version was in making it
possible to find out RTE_FUNCTION attribute types after planing, as it's
necessary to correctly handle joins. In this version
get_tupdesc_for_join_scan_tuples() doesn't handle function RTEs. This
means, when we try to find out type for attribute types for joins, we'll
get errors. This can be seen in queries like
UPDATE remote_tbl r SET b=CASE WHEN random()>=0 THEN 5 ELSE 0 END FROM
UNNEST(array[box '((2,3),(-2,-3))']) AS t (bx) WHERE r.a = area(t.bx)
RETURNING a,b;
Now it fails on earlier stages (with "column f2.c0 does not exist"), but
if we fix it, we'll get something like
"ERROR: input of anonymous composite types is not implemented"
Overall, function_rte_pushdown_ok() now allows more strange
constructions. Could it skip Vars from outside of joinrel->relids? Can
we safely ship function with parameters in arguments? I'm not sure.
4) Why do we restrict list_length(rte->functions) to 1? The main reason
for supporting several rte->functions was to allow pushdown of UNNEST()
with several arrays, which is used by HammerDB tproc-c test.
5) We can support pushing down joins of foreign tables and another RTE
types, for example, VALUES. But with new specific way of handling
RTE_FUNCTIONS in core, this requires both changes to
set_foreign_rel_properties() and postgres_fdw. Not sure, if this is a
big problem, but at least is worth mentioning .
--
Best regards,
Alexander Pyhalov,
Postgres Professional