> [!NOTE] Custom & Foreign Scans > <table> > <tr> > <td width="25%"><img src="assets/ex_customscanforeignscan.png"></td> > <td>Scans external data sources (Foreign Data Wrappers) or executes custom extension logic.</td> > </tr> > </table> > > ```sql > -- A self-contained file_fdw example using a tiny generated CSV stream > CREATE EXTENSION IF NOT EXISTS file_fdw; > CREATE SERVER lyap_local_files FOREIGN DATA WRAPPER file_fdw; > CREATE FOREIGN TABLE external_logs (id integer, message text) > SERVER lyap_local_files > OPTIONS ( > program 'printf ''1,started\n2,ready\n''', > format 'csv' > ); > > EXPLAIN (ANALYZE, COSTS, BUFFERS, VERBOSE) > SELECT * FROM external_logs; > ``` > > ![CustomScanForeignScan Plan Tree](assets/plan_tree_op_foreign_scan.svg) > > ```text > Foreign Scan on public.external_logs (cost=0.00..138.00 rows=1280 width=36) (actual time=4.577..4.578 rows=2 loops=1) > Output: id, message > Foreign Program: printf '1,started\n2,ready\n' > Planning: > Buffers: shared hit=29 > Planning Time: 0.054 ms > Execution Time: 4.873 ms > ``` > > ![Custom & Foreign Scans measured plan performance signature](assets/trace_op_custom_scan_foreign_scan.svg) > > <table> > <tr> > <td rowspan="2" width="25%"><img src="assets/ex_foreign_scan.svg"></td> > <td><b>Performance</b></td><td>Entirely dependent on the external source's latency and the efficiency of the Foreign Data Wrapper (FDW) or custom extension.</td> > </tr> > <tr><td><b>Cost</b></td><td>Defined by the FDW's custom cost model.</td></tr> > </table>