My select query taking long time in postgres foreign tables. It is taking 15sec in MSSQL server.
PostgreSQL 13.7 on x86_64-pc-linux-gnu, compiled by Debian clang version 12.0.1, 64-bit
I am querying two different database tables with the help of fdw
I was created extention for postgres cross database query
Both tables are from same server but different database
Here is my Query
select *
FROM table1
join table2
on table1."ID" = table2."ID"
limit 1000
Here is my explain plan.
Limit (cost=210.94..239.96 rows=60 width=3754)
Hash Join (cost=210.94..239.96 rows=60 width=3754)
Hash Cond: ((table1.""ID"")::text = (table2.""ID"")::text)
Foreign Scan on table1 (cost=100.00..126.38 rows=546 width=126)
Hash (cost=110.66..110.66 rows=22 width=3628)
Foreign Scan on table2 (cost=100.00..110.66 rows=22 width=3628)
Let me know how to improve my select query performance
I was tried increase of work_mem and creating indexes on ID columns on two tables but no luck.
Here is my Explain Analyze
Limit (cost=210.94..239.96 rows=60 width=3754) (actual time=389787.002..389790.955 rows=1000 loops=1)
Hash Join (cost=210.94..239.96 rows=60 width=3754) (actual time=389787.000..389790.879 rows=1000 loops=1)
Hash Cond: ((table1.""ID"")::text = (table1.""ID"")::text)
Foreign Scan on table1 (cost=100.00..126.38 rows=546 width=126) (actual time=12.722..13.047 rows=4065 loops=1)
Hash (cost=110.66..110.66 rows=22 width=3628) (actual time=389773.386..389773.388 rows=51371319 loops=1)
Buckets: 33554432 (originally 1024) Batches: 4 (originally 1) Memory Usage: 4737857kB
Foreign Scan on table2 (cost=100.00..110.66 rows=22 width=3628) (actual time=54.429..332881.164 rows=51371319 loops=1)
Planning Time: 0.212 ms
Execution Time: 392158.638 ms
Please any one help me to resolve this