Repository navigation
Description
Every query with values that is not already prepared on its connection asks the server for its parameter types first (Parse, Describe, Flush), waits for the answer, then sends Bind, Execute, Sync. That is two round trips.
- With
prepare: false, which PgBouncer in transaction mode, Supavisor and Hyperdrive require, it happens on every query with values, every time. - With
prepare: true, it happens on each connection's first run of a statement. On serverless, connections are often fresh. - A query waiting for its types also holds back the queries queued behind it on that connection.
porsager#1225 measured select ${'x'}::text at 290 ms against 145 ms for select 1, with 70 ms each way.
Why "skip it for plain values" is not safe here
node-postgres never asks, because it encodes every value the same way whatever the server's type. Postgres.js does not: Bind picks each value's serializer from the type the server reported, and strings and numbers infer type 0. Skipping the request would change what is stored:
- a string bound to
json/jsonbis JSON-encoded today; sent raw,'{"a":1}'would store an object instead of a string; - a string or number bound to a date or timestamp column goes through
new Date(x).toISOString()today; sent raw, the server parses it in the session time zone; - a number bound to
booleanencodes as false unless it istrue; sent raw,1would be true; - a string bound to
byteais hex-encoded today; customtypeswith afromlist run their serializer on the reported type.
Proposal
- Skip the request when every parameter already has a non-zero type (booleans, bigints, Dates, Uint8Arrays,
sql.typed). Nothing changes. - With
prepare: false, cache the parameter types the server reported, per pool, keyed by the inferred types plus the SQL text, with a size bound. The first run asks; later runs send Parse with the cached types in one round trip, so values are encoded exactly as today. Forget an entry when a type error follows a schema change. - With
prepare: true, the same cache serves a connection's first run of a statement another connection already described. - Sending values raw like node-postgres changes stored values, so it would only come as an opt-in option or in a major version.
Measurement
Noise (Vercel Fluid, Supabase transaction pooler, prepare: false) logs per-query durations from 2026-10-12. Several days on 4.4.1 are the baseline; the switch to the build with this change will be the only change deployed. Compared by median, p95 and p99 per query.
Related: porsager#736 removed the extra Flush so Hyperdrive could cache queries. It was closed because caching needs the Describe step skipped, which is the design question here.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsLater
Activity
okomarov commentedon Oct 13, 2026
Rescoped on 2026-10-13: no type cache. Sharing remembered answers across a pool needs heuristics to stay correct, such as text-matching DDL and
search_path. Each heuristic misses cases by construction, and a miss stores a wrong value silently.New scope:
sql.typed).1,'true','t'stored as false) and A JSON string sent to a json/jsonb column is stored as a JSON string, not the value it encodes #43 (JSON strings stored as strings), and stops date strings from depending on the app server's time zone.feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: add parameter_types: 'warn' to report values the planned 'clien…
feat: serialize values from their JavaScript type with parameter_type…
feat: serialize values from their JavaScript type with parameter_type…
chore: release 4.5.0-rc1
okomarov commentedon Oct 15, 2026
Available in 4.5.0-rc1 with
parameter_types: 'client'(npm install @steadybrew/postgresjs@next).parameter_types: 'warn'reports which of your queries 'client' would send differently; see Parameter types. This stays open until 'client' becomes the default in 5.0.okomarov commentedon Oct 17, 2026
Production result for
parameter_types: 'client', from one app withprepare: falsebehind the Supabase pooler: a day on'warn'(2026-10-15 15:02 → 2026-10-16 10:55 UTC, 4.5.0-rc1) against a day on'client'(2026-10-16 10:56 → 2026-10-17 10:48 UTC).'warn'takes the same two round trips as the default'server', and had reported no value that'client'would send differently.'warn''client''client'and 1 a higher one. The median change is −2.4 ms, one round trip to the pooler.update … attempts + 1, median about 106 ms) spend their time in the server; those shapes did not move.Limits: one app, one day per mode. This is the evidence for making
'client'the 5.0 default; this issue stays open until then.