Skip to content

Full-query pushdown support for FDW - #615

Open
bnjjj wants to merge 4 commits into
mainfrom
bnjjj/remote_query
Open

Full-query pushdown support for FDW#615
bnjjj wants to merge 4 commits into
mainfrom
bnjjj/remote_query

Conversation

@bnjjj

@bnjjj bnjjj commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Implement full-query pushdown support for FDWs built on supabase-wrappers.
The goal is to let an FDW act as a thin bridge to a remote execution engine: PostgreSQL can still participate in planning, but the selected query can be sent as one remote SQL statement instead of being decomposed into scan callbacks and partially executed locally.
This enables wrappers-based FDWs to delegate complete query execution, including joins, aggregates, projections, filters, ordering, limits, and parameters, while PostgreSQL only receives the final result rows.

bnjjj added 3 commits June 12, 2026 11:28
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 8, 2026 14:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds “full-query pushdown” plumbing to supabase-wrappers, allowing wrappers-based FDWs to execute an entire planned SQL statement remotely (including joins/upper ops) and return only final rows to PostgreSQL.

Changes:

  • Introduces full-query remote execution state (FullQuery, relations, parameters, policy/context) and wires it into planner join/upper paths plus executor scan dispatch.
  • Reworks FDW plan state handling to avoid storing transient planner pointers in cached plans (JSON snapshot for full-query plans; cloned plan templates for legacy scans).
  • Adds serde/serde_json dependencies to support serializing full-query plan snapshots.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
supabase-wrappers/src/utils.rs Makes list deserialization safer by avoiding an unconditional unwrap.
supabase-wrappers/src/upper.rs Adds a full-query upper-path option and improves null-safety in planner extraction helpers.
supabase-wrappers/src/scan.rs Implements full-query planning/execution path, plan snapshot serialization, and parameter capture for remote queries.
supabase-wrappers/src/interface.rs Adds full-query types and introduces remote_query_policy / begin_remote_query hooks for FDWs.
supabase-wrappers/Cargo.toml Adds serde + serde_json dependencies needed for plan snapshotting.
Cargo.lock Locks new serde-related dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1650 to +1653
match param.eval_value.lock() {
Ok(mut eval_value) => *eval_value = current_value,
Err(_) => debug2!("parameter evaluation cache lock was poisoned"),
}
Comment on lines +1708 to +1714
let value = match param.eval_value.lock() {
Ok(value) => value.clone(),
Err(_) => {
debug2!("remote-query parameter cache lock was poisoned");
None
}
};
Comment thread supabase-wrappers/src/interface.rs Outdated
Comment on lines +1063 to +1065
/// If enabled, wrappers may add foreign join or upper paths that call
/// [`begin_full_query_scan`] instead of decomposing the query into base
/// scans, filters, joins, aggregates, and projections executed by Postgres.
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
staticset added a commit to staticset/wrappers that referenced this pull request Sep 1, 2026
…own)

- trait impl on the PR supabase#615 hooks: supports_full_query_pushdown,
  remote_query_policy (Require when all relations are foreign),
  begin_remote_query -> single translated T-SQL round-trip via tiberius
- translator.rs: pure PG-SQL -> T-SQL (relations rename, quoted idents,
  $n -> @pn typed params, casts, || -> +, ILIKE, bool predicates,
  LIMIT/OFFSET -> TOP / OFFSET-FETCH, structured UnsupportedConstruct
  errors); 27 unit tests, no PG needed
- types.rs: TZ §5.5 type map, param binding (values never concatenated),
  result row conversion (uuid/date/timestamp included; bytea/time next)
- SQL auth via CREATE USER MAPPING (user/password|password_id, read
  through pg_sys::GetUserMapping) or User=/Password= in conn_string
- validator for server/table/user-mapping options; read-only guard;
  log_remote_query server option (LOG-level with duration)
- fix clippy uninlined_format_args in PR supabase#615 core scan.rs

Co-Authored-By: Claude <noreply@anthropic.com>
staticset added a commit to staticset/wrappers that referenced this pull request Sep 2, 2026
…ype round-trip, e2e suite

- bool_columns: catalog lookup via pg_attribute by schema.table (name cast
  to text), wired into begin_remote_query; bare bit predicates rewrite to
  = 1 / = 0
- types: bytea (varbinary) and time round-trips, date/time/timestamp/
  timestamptz/bytea parameter binding, parts-based datetime conversions
  with sub-second precision; tolerant int/numeric/float reads (T-SQL
  COUNT/SUM(int) return int32 where Postgres expects int8)
- translator: fix infinite loop on IS NOT NULL (early passthrough now
  advances); pg_get_querydef specifics — multi-line input, FROM ONLY
  dropped, top-level comma lists in WHERE/HAVING/ON become AND, PG
  OFFSET..FETCH form re-emitted canonically, SQL typed literals
  (DATE '...') become CASTs, unmappable typed literals and unknown
  function calls rejected explicitly
- core (PR supabase#615 follow-up): deparse only at the executable plan node;
  document the debug_query_string fallback for join trees (SPI/PL-pgSQL
  limitation); FDW refuses statement texts that do not mention the
  foreign tables
- e2e (cargo pgrx test, rqtest): 8 tests covering the TZ §10 acceptance
  set — filter, JOIN+SUM+HAVING+OFFSET/FETCH (via dblink top-level,
  compared against direct MSSQL), PREPARE $1, DISTINCT, read-only,
  type round-trip incl. bytea/time/timestamptz, bare boolean
  predicates, EXPLAIN Foreign Scan without local Sort/Aggregate/Join
- dev contour: USER=dev env for the pgrx test framework

Co-Authored-By: Claude <noreply@anthropic.com>
staticset added a commit to staticset/wrappers that referenced this pull request Sep 2, 2026
…ng, kerberos, CI

- window functions translate and execute as ONE remote statement
  (row_number/rank/dense_rank/ntile/lag/lead/first_value/last_value,
  aggregates OVER (PARTITION BY …)); e2e compares against direct MSSQL
- NULL ordering: PG's implicit semantics (ASC→NULLS LAST, DESC→NULLS
  FIRST) reproduced with CASE tiebreakers for nullable top-level keys;
  window sort keys must be NOT NULL columns (explicit error otherwise);
  explicit NULLS FIRST/LAST matching T-SQL defaults are dropped
- deparser LIMIT forms: 'n'::bigint constants and FETCH FIRST n ROWS
  ONLY (no OFFSET) both map to TOP/OFFSET-FETCH
- streaming executor: background task + bounded mpsc channel; rows are
  pulled one at a time in iter_scan, end_scan cancels the task; rescan
  rejected explicitly (one round-trip preserved)
- kerberos: mssql_fdw_rq_kerberos feature (tiberius integrated-auth-
  gssapi), server option auth='kerberos' → AuthMethod::Integrated;
  manual keytab/SPN checklist in README (CI covers the build only)
- CI: .github/workflows/mssql-fdw-rq.yml — pg15+pg17 matrix against a
  live MSSQL 2022 service (rqtest init), fmt/clippy/unit/e2e + kerberos
  build check
- core (PR supabase#615 follow-ups): full-query upper paths for inputs without
  fdw state (fresh instance from the first relation's server);
  append_rel_list counts as an upper operation (simple UNION ALL arms);
  documented set-operation limitation: PostgreSQL offers no FDW hooks
  at the setop root, arms push down individually (as in postgres_fdw)
- README: M2 status, options incl. auth, kerberos checklist, explicit
  limitations (setop, SPI joins, rescan, LOB(MAX))

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants