CommitFest 7269 Review: postgres_fdw WITH TIES Pushdown

code-review · generated from canonical Markdown

Type
code-review
Source
postgresql-master
Slug
commitfest-7269-review
Tags
code-reviewcoveragepatch-review
Updated
2026-09-14T03:29:27.934867+00:00
Verdict / Summaryready-for-committer
Front matter
schema: review-report-v2
target: postgres_fdw: push down FETCH FIRST .. WITH TIES when server version allows (CommitFest 7269)
head: 4000ab1decb6138a11fb4423237589376cb9ff54
base: 4000ab1decb6138a11fb4423237589376cb9ff54
diff_identity: diff:80c811bed6fd700cfd81b34ff5e04c11f0123219
verdict: ready-for-committer
blocker_counts:
  verified: 0
  unverified: 0

CommitFest 7269 Review: postgres_fdw WITH TIES Pushdown

Summary

Verdict: ready-for-committer

The patch enables pushdown of FETCH FIRST .. WITH TIES to remote PostgreSQL servers in postgres_fdw when a cached connection already exists for the session and reports version >= 13. It adds GetCachedConnectionVersion() which consults the connection cache without performing network I/O, modifies add_foreign_final_paths() to check the cached version before allowing pushdown, and updates appendLimitClause() to emit the SQL-standard FETCH FIRST ... ROWS WITH TIES syntax with parenthesized values to work around the c_expr grammar restriction.

The approach is safe, well-designed, and addresses a known limitation documented in commit 2b461efc519 (which disabled WITH TIES pushdown due to bug #18467). The design avoids plan-time network I/O by only using already-cached connection versions.

Findings

IDSeverityClassLocationVerificationRepair
F1NITmaintainabilityconnection.c:1047verifiedpassed
F2MINORperformancepostgres_fdw.c:8543verifiedpassed
F3NITcorrectnesspostgres_fdw.c:8543verifiedpassed
F4NITtestspostgres_fdw.sql:471verifiedpassed
F5NITcorrectnesspostgres_fdw.c:8545cannot-verifywaived
COV-2NITtestspostgres_fdw.c:8539verifiedpassed
COV-3NITtestspostgres_fdw.c:8541verifiedpassed

Blocker counts: 0 verified, 0 unverified.

Verification Summary

Repair Validation Summary

FindingPatch SHA-256ValidationMethods
F1dafa9ad4...passedapply-check, diff-check, compile, static-check, targeted-test
F2aa832a32...passedapply-check, diff-check, compile, targeted-test
F3aa832a32...passedapply-check, diff-check, compile, repro, targeted-test
F43adfe6e2...passedapply-check, diff-check, targeted-test
F5waivedwaiveddesign-choice waiver
COV-23adfe6e2...passedapply-check, diff-check, targeted-test
COV-33adfe6e2...passedapply-check, diff-check, targeted-test

All validated patches were built and tested in a disposable scratch build with --enable-debug --enable-cassert --without-readline --without-zlib --without-icu and coverage instrumentation. The postgres_fdw regression tests (postgres_fdw, query_cancel) and isolation test (eval_plan_qual) all passed.

Changed-Code Coverage

Coverage requirement: required (3 changed instrumentable implementation files)

Measurement: fresh disposable counter epoch, host-disposable lane, PostgreSQL 20devel, gcov.

Totals

MetricCount
Changed executable lines31
Covered changed lines28
Compiler-uncovered changed lines3
Uncovered changed lines3
Structural uncovered lines0
Changed branches18
Covered changed branches13

Line coverage: 28/31 = 90.3% Branch coverage: 13/18 = 72.2%

Test commands

make -C contrib/postgres_fdw installcheck PGPORT=55432 PGHOST=/tmp
pg_isolation_regress --load-extension=postgres_fdw --dbname=isolation_regression eval_plan_qual

Uncovered regions (actionable)

  1. connection.c:1052 (GetCachedConnectionVersion) — return 0 when ConnectionHash == NULL. Defensive guard; requires fresh session with no prior connections. Classification: requires-special-harness-or-injection-point. TAP test proposed.
  1. postgres_fdw.c:8539 (add_foreign_final_paths) — return when !OidIsValid(final_rel->serverid). Cross-server WITH TIES early return not reached by existing tests. Classification: coverable-now. Regression test with partitioned table proposed (COV-2).
  1. postgres_fdw.c:8541 (add_foreign_final_paths) — pushdown_userid = final_rel->userid (ternary true branch). Security definer view userid branch never taken. Classification: coverable-now. Regression test with security definer view proposed (COV-3).

Uncovered branches

Non-instrumented changes

pgsql-hackers Thread Ledger

Status: no-thread-found

The patch submission thread (Message-ID: CAPhYifHu_Nd+YoAg0iWfCCO+6eGo5nzbQNyOm=uxXTcvKatccw@mail.gmail.com, 2026-09-06) has only the original patch post by Sagar Shedge with no review replies. The referenced bug #18467 discussion is a separate prior thread. No pgsql-hackers review discussion exists for this patch.

All findings are disposition new (not previously raised in the thread).

Security Section

No security vulnerabilities found. The patch is safe to merge from a security standpoint:

Aggregated Test Plan

  1. Existing tests: WITH TIES pushdown (warm cache), WITH TIES + OFFSET pushdown, cross-server join (no pushdown), UNION ALL with mixed cache states — all pass.
  2. F3 repro: Missing user mapping at plan time — verify no ERROR, local Limit plan.
  3. COV-2 test: Cross-server partitioned table WITH TIES — verify local Limit, no pushdown.
  4. COV-3 test: Security definer view WITH TIES — verify pushdown with view owner's connection.
  5. F4 deterministic test: UNION ALL with both connections warmed up — verify both sides push down.

Provenance

Residual Risk