I have a table on database temp_db named external_objects and an index on the field id, which is an MongoDB id (like 5458d717cd07870859000003). When I explain this select at this database, I got this
explain verbose SELECT origin_id
from external_objects
where id = '5458d717cd07870859000003'
"Index Only Scan using eoid_lookup_tmp_ix1 on public.external_objects (cost=0.56..8.57 rows=1 width=16)"
" Output: origin_id"
" Index Cond: (external_objects.id = '5458d717cd07870859000003'::text)"
I connected this table to another database, via postgres_fdw with
-- Creating external_objects table
CREATE FOREIGN TABLE external_objects_mosql
(
id text NOT NULL,
created_at date,
origin_id text,
_extra_props text
) SERVER mosql_data OPTIONS (table_name 'external_objects', schema_name 'public');
on the staging server, but when I try explain the same query on this foreign table, I see this
explain verbose SELECT external_objects_mosql.origin_id
from external_objects_mosql
where external_objects_mosql.id = '5458d717cd07870859000003'
"Foreign Scan on public.external_objects_mosql (cost=100.00..147085.60 rows=1 width=16)"
" Output: origin_id"
" Remote SQL: SELECT origin_id FROM public.external_objects WHERE ((id = '5458d717cd07870859000003'::text))"
Seems like that when using postgres_fdw, I'm unable to use indexes, and this is costing me too much time. is there any workaround for this?
EXPLAIN ANALYZEfor both queries.