Skip to content
Farolan Faisal

Backend & data engineering

I find out why a query costs what it costs, then fix it and prove the fix.

Most of my work is PostgreSQL performance inside larger systems — a production Rails application, a service where a single request fans out into hundreds of statements. The interesting part is almost never the index. It is the plan the planner chose, the type it was handed, or a model callback doing a table scan nobody asked for.

I write that work up here, and every measurement in every article has a reproduction you can run.

Worked example

The same id list, one type wider than the column, cost 245x.

`= ANY($1::bigint[])` against an `int4` column cannot use a hash, so the array is walked once per row. The same query with the array cast to the column's own type is 300x faster and returns the same rows.

It is a one-line change to the parameter, and it is the kind of thing that survives review because the plan prints the same sentence either way.

Read the write-up, with the benchmark →
Measured
9.89 s40 ms

244.505x · postgres:16-alpine · 3 rounds

Same result set from every arm. Reproduce it with npm run bench.

Selected work

All work →