pub trait ForeignDataWrapper: Send + Sync {
// Required methods
fn kind(&self) -> &'static str;
fn scan(
&self,
server_state: Option<&Arc<dyn WrapperState>>,
table_options: &FdwOptions,
) -> Result<Vec<UnifiedRecord>, FdwError>;
// Provided methods
fn build_server_state(
&self,
_options: &FdwOptions,
) -> Result<Option<Arc<dyn WrapperState>>, FdwError> { ... }
fn supports_pushdown(&self) -> bool { ... }
fn estimated_row_count(
&self,
_server_state: Option<&Arc<dyn WrapperState>>,
_table_options: &FdwOptions,
) -> Option<usize> { ... }
}Expand description
Core trait every FDW implements.
Phase 3.2 is read-only — scan is mandatory; insert / delete
are defaulted to “not supported” so wrappers can opt-in. Filter
pushdown is also opt-in via supports_pushdown; the runtime
checks that before handing the wrapper the predicate AST.
Required Methods§
Sourcefn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Unique identifier for the wrapper kind (e.g. “csv”, “postgres”).
Matches the FOREIGN DATA WRAPPER <name> clause in DDL.
Sourcefn scan(
&self,
server_state: Option<&Arc<dyn WrapperState>>,
table_options: &FdwOptions,
) -> Result<Vec<UnifiedRecord>, FdwError>
fn scan( &self, server_state: Option<&Arc<dyn WrapperState>>, table_options: &FdwOptions, ) -> Result<Vec<UnifiedRecord>, FdwError>
Stream rows from the foreign table. table_options merges the
server’s options with the table’s options (table takes priority
on conflicts). filter is opaque to the wrapper unless it
advertises pushdown via supports_pushdown.
Provided Methods§
Sourcefn build_server_state(
&self,
_options: &FdwOptions,
) -> Result<Option<Arc<dyn WrapperState>>, FdwError>
fn build_server_state( &self, _options: &FdwOptions, ) -> Result<Option<Arc<dyn WrapperState>>, FdwError>
Validate + materialise a server’s options. Called once on
CREATE SERVER and cached on ForeignServer. Wrappers that
don’t need per-server state return Ok(None).
Sourcefn supports_pushdown(&self) -> bool
fn supports_pushdown(&self) -> bool
Whether the wrapper can evaluate a SQL WHERE predicate natively.
When true, the planner will hand the AST to scan_with_filter;
when false, the runtime applies the filter after the scan.
Sourcefn estimated_row_count(
&self,
_server_state: Option<&Arc<dyn WrapperState>>,
_table_options: &FdwOptions,
) -> Option<usize>
fn estimated_row_count( &self, _server_state: Option<&Arc<dyn WrapperState>>, _table_options: &FdwOptions, ) -> Option<usize>
Estimated row count — drives planner cost. None means the
wrapper has no cheap way to estimate and the planner falls back
to its default assumption.