mysql

  • A foreign key is an index you did not have to name

    InnoDB requires an index on the referencing column and creates one silently if none exists, which is convenient and produces indexes nobody chose. The auto-created index is a…

  • A test that queries for data it did not create

    A test calling first() depends on whatever happens to be in the database, which is an ordering dependency nobody wrote down. The failure only appears under a randomised…

  • LATERAL, for a top-N per group without a window function

    A correlated derived table can reference columns from the row it is joined against, which expresses top-N-per-group directly. A window function with ROW_NUMBER reads more clearly and computes…

  • data_free, and the 80% of the file that is nothing

    InnoDB reuses freed space within a table and does not return it to the filesystem, so a table deleted from daily can be mostly empty and full size.…

  • Claiming a message and doing the work in one transaction

    Recording that a message was handled and doing the work are two writes, and a crash between them is either a duplicate or a silent loss. Claiming outside…

  • The site editor writes templates to the database

    A template edited in the site editor becomes a wp_template post, and from that moment the file on disk is ignored for that template. This is the single…

  • An append-only table, enforced by a grant

    An audit table that the application can update is an audit table that a compromised application can rewrite. The grant is the practical control and the trigger is…

  • Backed enums, and the column type that finally matches

    A status column had held strings for six years, with no constraint anywhere and three spellings of shipped in production. The backing type must be int or string…

  • A deploy that can be undone in ninety seconds

    The rollback plan was “redeploy the previous tag” and it took nineteen minutes. Rolling back is a build, and a build is not fast.

  • Enums, and the string column that was pretending

    8.1 on 25 November, and the feature PHP had been simulating with class constants for a decade. A status column holding three spellings of the same thing.