mysql

  • The foreign key we added six years late

    A column named customer_id with no constraint, and 312 rows pointing at customers that had been deleted. Deciding what to do with the orphans is the work —…

  • A migration with a batch size and a sleep

    Updating four million rows in one statement holds a transaction open long enough for the replica to fall twenty minutes behind. The sleep is not politeness, it is…

  • A CHECK constraint that documents a JSON shape

    A JSON column accepts anything, which is the feature and is also how a column ends up with four different shapes in it. The constraint is enforced on…

  • EXPLAIN ANALYZE, and an estimate that was out by 40x

    The optimiser chose a plan based on an estimate of 200 rows where the real answer was 8,000, and only the actual execution shows the difference. The gap…

  • A backup we restored on purpose, every month, forever

    A backup that had run nightly for four years and had never been restored. The first restore produced a database missing one table.

  • Multi-valued indexes on a JSON array, and the CAST

    Filtering on a value inside a JSON array was a full scan until 8.0.17 added multi-valued indexes, and the syntax is unforgiving. The ARRAY keyword in the cast…

  • A read replica, and the six queries that could not use it

    A primary at 80% CPU and reports running during the working day. Setting up the replica takes an afternoon; the consistency model takes a month.

  • An outbox table, and the relay that reads it

    Publishing to a broker inside a database transaction is two systems and one commit, which cannot be made atomic. The index on (published_at, id) with nulls first is…

  • Extracting a module without extracting a service

    A billing module everybody agrees should be separate, a team of four, and 88 classes that reference it. The boundary, drawn in code rather than in conversation.

  • A full-text index has a minimum word length you will hit

    InnoDB full-text ignores words shorter than three characters and words appearing in more than half the rows, and both are configurable only at the server level. Changing innodb_ft_min_token_size…