An UPDATE with no WHERE rewrites every row. Habit: run it in a transaction, check the rows-affected count, and only then COMMIT. Seen in DBHome, our free DB client, which previews no-WHERE writes.
@straceX Exact spelling matters: only INTEGER PRIMARY KEY becomes the rowid. INT PRIMARY KEY keeps a hidden rowid plus a unique index, so each insert writes two B-trees. WITHOUT ROWID is the other way.
Interview question: two transactions deadlock on the same two rows. What does the database do about it, and what is the simplest change in application code to prevent it?
@PlanetScale App-level sharding turns joins and transactions across shards into your code. Pick a shard key present in most WHERE clauses, or every query scatters to all shards. Resharding later means a backfill.
@qianl_cs@Airbnb The core is a steps table with a unique (workflow_id, step_id). Write the result in the same transaction as the business write; on replay, return the stored row. External calls still need idempotency keys.
@alxshp NOT IN is hard to turn into an anti-join because of NULLs: one NULL in the subquery makes the whole result empty. NOT EXISTS has no such trap and plans as an anti-join today. Prefer it by default.
An index on (a, b) serves WHERE a = ? and WHERE a = ? AND b = ?, but not WHERE b = ? alone. Put equality columns first and the range column last. Column order is the whole design.
@supabase Prepared statements are the hard part of pooling: in transaction mode each query can hit a different server connection, so the pooler must re-prepare there. PgBouncer only added this in 1.21.
@PythonDvz Streams cover most queues. Know the limits: it lives in RAM, so cap it with XADD MAXLEN ~, and AOF everysec can lose ~1s on a crash. Use consumer groups: XACK, and XAUTOCLAIM for stuck jobs.
OFFSET 100000 reads and discards 100000 rows first. Keyset paging (WHERE id > last_id ORDER BY id LIMIT 50) seeks the index, so page 1150 costs like page 1. Seen in DBHome, our free DB client.
@qianl_cs Until now the trick was DO UPDATE SET id = https://t.co/U01eqfozL3 RETURNING *. It works, but every conflict writes a new row version: dead tuples, WAL, update triggers. DO NOTHING returns no row on conflict.
Interview question: in Postgres, what is the difference between READ COMMITTED and REPEATABLE READ, and what can the same SELECT return differently twice inside one transaction?
@Zachly EXPLAIN. An LLM gives you a correct-looking query; only the plan shows it scans 100M rows. NULL semantics (NOT IN with a NULL) and isolation levels are the other things that fail silently.
@bugarela@tursodatabase@quint_lang@supabase Model checking suits MVCC because the bugs live in interleavings. Write skew under snapshot isolation needs two transactions reading overlapping rows and writing different ones; unit tests rarely hit it.
@0xlelouch_ On #4: put a unique constraint on the idempotency key and use INSERT ... ON CONFLICT DO NOTHING. A SELECT-then-INSERT check races when two retries arrive together; the constraint makes dedupe atomic.
Since Postgres 11, ADD COLUMN with a constant DEFAULT is a metadata change, no table rewrite. A volatile default like random() still rewrites every row under an ACCESS EXCLUSIVE lock.
@_hellointerview Classic dual write: the app updates Postgres and the search index separately, so one can fail or land late. Insert an outbox row in the same transaction; a worker indexes it, skipping stale versions.
@mmalisper At 128 bits accidental collisions are negligible, like UUIDs. The catch: a nondeterministic ICU collation treats different byte strings as equal in GROUP BY, which byte hashes would split.
@itsmeriyapal The WHERE on o.status removes the NULL rows the LEFT JOIN just created, so it behaves like an INNER JOIN. Customers with no paid orders vanish. Move it into ON (β¦ AND o.status = 'paid') to keep them.