indexing

  • The leftmost prefix rule, in one example

    A composite index on (a, b, c) serves queries filtering on a, on a and b, and on all three — and does nothing for a query filtering…

  • A covering index turns two reads into one

    An index lookup finds the primary key and then reads the row from the clustered index to get the other columns, which is a second read per row…

  • The N+1 that does not appear in the query log

    340 queries on a page showing twenty rows, and none of them are slow. Every one is under the threshold, which is why the slow log has nothing…

  • Window functions replace a habit

    8.0 went GA in April and the correlated subquery can retire. The plans before and after, the recursive CTE that replaces a loop, and the upgrade nobody expects.

  • Descending indexes are real in 8.0

    Earlier versions accepted DESC in an index definition and ignored it, which is worse than rejecting it because the query looked optimised and was doing a filesort. It…

  • Rank rows within a group in one query

  • An invisible index tests a drop without doing it

    Dropping an index that turns out to be load-bearing means rebuilding it on a large table under pressure, so unused-looking indexes accumulate for years because nobody wants to…

  • An index that helps reads and halves your write throughput

    Every index is maintained on every insert, update and delete touching its columns, so an index added to fix one report is paid for by every write to…

  • A covering index for a sort, not just a filter

    Covering indexes are usually explained in terms of avoiding a row lookup. The other half is that an index is already ordered, so a sort matching the index…

  • Generated columns can be indexed and cannot be written

    A value derived from other columns is usually maintained by application code or a trigger, and both drift. A generated column is computed by the server and cannot…