Posts about performance
Articles, guides and engineering notes about performance from the Relyt One team.
9 articles

Why is COUNT(*) slow in Postgres? We measured it on 10 million rows
Why SELECT count(*) in PostgreSQL reads the whole table, and what to do instead. Measured on 10 million rows on Postgres 17.11: sequential vs parallel vs index-only scans, how an UPDATE of 1% of rows made an indexed count 40 to 50 times slower until VACUUM ran, count(*) vs count(1), planner estimates, capped counts, and the write cost of trigger-maintained counter tables.

Postgres JSONB indexes: jsonb_ops vs jsonb_path_ops vs expression indexes, and the queries each one ignores
Which index to create for a JSONB column in PostgreSQL: the default GIN operator class, jsonb_path_ops, or a B-tree expression index. Measured on 1 million rows on Postgres 17.11: query times, index sizes and insert cost, why WHERE payload->>'key' = ... never uses a GIN index, why ? ignores jsonb_path_ops, and the partial-index statistics trap.

Postgres UNLOGGED tables: how much faster they really are, and exactly what you lose
We measured UNLOGGED tables on PostgreSQL 17.11: a million-row bulk load took only 17% less time, small cache writes were 2.9× faster, reads didn't change, and synchronous_commit = off on a normal table came within a few percent of the same speedup. Then we crashed the server to show what you lose, and explain why a serverless suspend counts too.

Keyset pagination in Postgres: why OFFSET gets slow on deep pages, and the cursor query that doesn't
Why LIMIT/OFFSET pagination slows down page after page in PostgreSQL and returns duplicate or missing rows while data changes, and how keyset (cursor, seek) pagination with a row comparison and a matching index fixes both. Includes measurements on 1,000,000 rows, previous-page and has-more queries, and four traps: non-unique sort keys, NULLs, mixed sort directions and missing indexes. Every query replayed on Postgres 17.11.

Postgres full-text search in practice: tsvector, GIN, websearch_to_tsquery, and the queries that silently return nothing
A hands-on guide to PostgreSQL full-text search: a stored tsvector column with weights, a GIN index, websearch_to_tsquery for raw user input, ts_rank and ts_headline. Covers the five mistakes that make search return zero rows or skip the index, with timings on 200,000 documents: about 900 ms for ILIKE, 14 seconds for to_tsvector at query time, and 2 ms with a GIN index. Every query tested on Postgres 17.11.

The fastest way to bulk insert into Postgres: 7 methods measured at 0.1, 2 and 8 ms of latency
Row-by-row INSERT, one big transaction, executemany with pipeline mode, multi-row VALUES, unnest arrays and COPY, timed on PostgreSQL 17.11 with 10,000 rows and three network round-trip times. Why COPY is ~100× faster on localhost and over 1,000× faster over a network, and what changes behind a transaction pooler.

Postgres window functions in practice: top-N per group, running totals, streaks, and the frame that trips everyone up
A hands-on guide to PostgreSQL window functions: ROW_NUMBER vs RANK vs DENSE_RANK, top-N per group, running totals and moving averages, LAG and LEAD, gaps and islands, sessionization, and deduplication. Explains the default window frame behind most wrong answers, the last_value trap, and when a LATERAL join beats a window function by more than 100x. Every query tested on Postgres 17.11.

UUIDv7 vs bigint vs UUIDv4 primary keys in Postgres 17: we measured the difference
Index size, page splits, WAL volume and insert cost for bigint identity, random UUIDv4 and time-ordered UUIDv7 primary keys, measured on PostgreSQL 17.11 with 5 million rows. Includes a UUIDv7 function for Postgres 17 that builds an index as compact as Postgres 18's built-in, and why the simple millisecond version doesn't in bulk loads.

Why Postgres isn't using your index: seven causes, with EXPLAIN output you can reproduce
You created the index and EXPLAIN still shows a sequential scan. Seven reasons PostgreSQL ignores an index (functions, casts, wildcards, selectivity, stale statistics, column order, tiny tables), each with a reproduction and a fix.