Skip to content

perf(postgres): stable browse pages, batched catalog reads, streamed reads and direct TLS - #4328

Merged
datlechin merged 2 commits into
mainfrom
perf/postgres-round-trips
Nov 18, 2026
Merged

datlechin merged 2 commits into
mainfrom
perf/postgres-round-trips

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • P2: every PostgreSQL session turns off synchronize_seqscans, so unsorted browse pages no longer skip rows on large tables. The setting is guarded by pg_backend_pid() = PQbackendPID, so a pooler's server session is left alone. PGlite, KingbaseES, Redshift and CockroachDB never send it, and -c synchronize_seqscans=... in Connection Options wins.
  • P6: connect sends the schema read, the catalog probes, statement_timeout and the scan setting in one Query. applyQueryTimeout skips the value the connect already applied, once.
  • P6: fetchColumns and fetchAllColumns send their 5 reads in one Query. Inside a user's block a savepoint holds the batch and is rolled back after it; an aborted block keeps each read on its own.
  • P14: build-libpq.sh and build-freetds.sh compile with -O2. Flags only, the libraries are not rebuilt here.
  • P22: every extended-protocol read goes through single-row mode, so an uncapped result is never held twice.
  • P22: bytea decodes from libpq's wire bytes instead of through String.
  • P34: TLS connects to a PostgreSQL 17+ server already proven direct use sslnegotiation=direct. A refusal before sign-in retries the standard negotiation under the same sslmode, and that endpoint is not tried directly again.
  • check-column-type-corpus.sh lists the products the PostgreSQL harness now needs.

Measurements

PostgreSQL 17.11, shared_buffers 128 MB, 200 ms RTT through a delay proxy where a time is given.

Item Scenario Before After
P2 30 pages of 5,000 rows, 1,000,000-row table, distinct rows of 150,000 141,256 to 148,248 150,000
P2 Highest id read in those pages 949,560 to 1,000,000 150,000
P6 Connect 1,035 ms, 5 flights 617 ms, 3 flights
P6 fetchColumns 1,050 ms 218 ms
P22 Fetch All, 1,000,000 rows, peak footprint 445 MB 284 MB
P22 Decode a 16 MiB bytea 225 ms 13 ms
P34 TLS connect, sslmode=require 1,662 ms 1,261 ms first, 1,042 ms after
P34 Proxy that refuses direct TLS not applicable connects, 1,230 ms

Test plan

  • New: LibPQCatalogBatchTests, LibPQSingleRowReadTests, LibPQDirectTLSTests, plus cases in LibPQConnectionStringTests, LibPQCellDecodingTests and LibPQByteaDecoderTests.
  • Updated on purpose: PostgreSQLConnectRoundTripTests.probesShareOneQuery, since the connect's Query now opens with the schema read instead of the search path pin.
  • PostgreSQLDriverTests: 917 passed. AllPlugins builds.
  • check-column-type-corpus.sh postgresql against 17.11: 469 checks hold.
  • fetchColumns and fetchAllColumns output is identical before and after on a table with enum, array, collated and generated columns.
  • verify.sh ios was inconclusive, this Mac has no iOS runtime. CI covers PostgreSQLCatalogExport.swift on iOS.

Needs the maintainer

  • Rebuild libpq and FreeTDS for every architecture, publish them and update apple/Libs/checksums.sha256. The -O2 flags take effect only then.

@datlechin
datlechin enabled auto-merge (squash) November 18, 2026 16:52
@datlechin
datlechin merged commit d9676db into main Nov 18, 2026
11 checks passed
@datlechin
datlechin deleted the perf/postgres-round-trips branch November 19, 2026 02:02
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.

1 participant