A select from a foreign wrapped view takes 15+ times longer to complete than the direct select on the source database.
Tried Adding USE_REMOTE_ESTIMATE 'true' to the foreign server. Also tried killing the where clause altogether (baking it into the view), so I know there are no predicate/aggregate pushdown issues!
-- On source system (massively complex union of 200 schemas), AWS RDS PG 9.5
explain verbose select * from stats where company_id = 26531;
-- [ 2125 lines of stuff!]
select * from stats where company_id = 26531;
-- completes in 1 - 2.5 seconds
-- From FDW (entirely different AWS RDS instance w/ PG 11)
explain verbose
select * from remoteschema.stats where company_id = 26531;
/*
Foreign Scan on stats (cost=311780.75..323299.91 rows=306770 width=394)
Output: columns
Remote SQL: SELECT columns FROM remoteschema.stats WHERE ((company_id = 26531))
*/
select * from remoteschema.stats where company_id = 26531;
-- completes in 20 seconds
There are no intermediate results to ship (no local joins), so I can't figure out why so slow. I've read PG 9.5 FDW has issues that later versions addressed. Is it that I just have to upgrade that database?