Repository navigation
Description
Summary
PgCache 0.9.3 does not cache parameterized full-row SELECTs from Bun SQL + Drizzle when the result mixes column types (for example, an integer and a text column in the same row).
The same SQL is cacheable when sent through psql/simple Query, and Bun queries that return a single column type are also cached. The missing case is the common ORM shape: Bun sends a named prepared statement, Describe('S'), and a per-column result format list such as [1, 0].
This matters because batch row reads and reporting queries often select full rows with mixed types. Those reads currently pass straight through PgCache.
Environment
- PgCache:
0.9.3(Docker image) - Cache PostgreSQL: 18
- Origin PostgreSQL: 18
- Origin path: PgCache → PgDog 0.1.66 → PostgreSQL
- Client: Bun
1.4.4 - ORM: Drizzle ORM
1.0.0-rc.6(drizzle-orm/bun-sql/postgres)
Minimal reproduction
Use a scratch table:
CREATE TABLE t (
id integer PRIMARY KEY,
name text NOT NULL
);
INSERT INTO t VALUES (1, 'one'), (2, 'two'), (3, 'three');Then run this three times through PgCache:
import { SQL } from "bun";
const sql = new SQL("postgres://user:pass@pgcache:5432/db");
for (let i = 0; i < 3; i++) {
await sql.unsafe("SELECT id, name FROM t WHERE id = $1", [1]);
}Our application-level batch-read helper produces the same shape with WHERE id IN ($1, $2, $3); it builds the query with Drizzle.
I verified this on a uniquely named scratch table in the test database and removed it afterwards.
Expected result
Repeated identical parameterized full-row SELECTs should be registered and served from PgCache on the next call, as they are for simple Query and for single-column results.
Actual result
The query is forwarded every time. It is not registered in /status, and the counters show:
pgcache_queries_uncacheable +3
pgcache_queries_cacheable 0
pgcache_queries_cache_hit 0
prepare: false does not help:
const sql = new SQL({ url: "postgres://user:pass@pgcache:5432/db", prepare: false });
for (let i = 0; i < 3; i++) {
await sql.unsafe("SELECT id, name FROM t WHERE id = $1", [1]);
}Metrics after this variant:
pgcache_queries_uncacheable +3
pgcache_queries_cacheable 0
pgcache_queries_cache_hit 0
Protocol capture
Default Bun path:
Parse statement="P0" query="SELECT id, name FROM t WHERE id = $1" param_oids=[23]
Describe 'S' "P0"
Bind portal="" statement="P0" param_formats=[1] result_formats=[1, 0]
Execute
Sync
result_formats=[1, 0] means column 1 is binary and column 2 is text.
With prepare: false, the statement is unnamed but the read is still not cached:
Parse statement="" query="SELECT id, name FROM t WHERE id = $1" param_oids=[23]
Describe 'S' ""
Bind portal="" statement="" param_formats=[1] result_formats=[]
Execute
Sync
What is cacheable
The same SQL is cached through psql/simple Query:
SELECT id, name FROM t WHERE id = 1;The query is accepted as cacheable, and a repeated call increments pgcache_queries_cache_hit.
Bun's simple-query path also works:
await sql.unsafe("SELECT id, name FROM t WHERE id = 1");Single-column results are cached even through the parameterized Bun path. For example, a Drizzle query returning only an integer was registered and hit repeatedly:
SELECT id FROM t WHERE id = $1
So the limitation is not Bun itself and not the query shape; it is the request format combination used by Bun for mixed-type full rows.
Possible directions
- Accept
ResultFormats::PerColumn(...)inexecute_cache_candidate()and serve cached rows encoded in the requested per-column formats. This is the main blocker for Bun/Drizzle full-row queries. - Support
Describe('S')when the statement has no cachedparameter_descriptionyet, including unnamed statements that are re-parsed on each execution. Theprepare: falsecapture suggests this may be a second blocker; please confirm whether that is expected. - If supporting this is not desirable, documenting the limitation and a supported client-side workaround would be helpful.
The relevant check in src/proxy/connection/extended.rs currently returns None for:
if let ResultFormats::PerColumn(_) = portal.result_formats {
return None;
}
if describe == PipelineDescribe::Statement && stmt.parameter_description.is_none() {
return None;
}Notes
- I have not tested with a different client driver yet; Bun is the production client in this setup.
- The query shapes themselves are supported by PgCache (single table,
IN, joins, grouped aggregates, etc.). For the default Bun path, the blocker appears to be the per-column result format handling, with the unnamed-statementDescribe('S')case as a likely second issue.
Activity
james-pgcache commentedon Nov 23, 2026
thanks - I was able to reproduce the error and so have a reliable test case.