Category: Layer 3: The Database Depths

MySQL: slow queries and corrupted tables.

  • Slow Query Slime

    Slow Query Slime

    Layer
    3. The Database Depths
    Type
    Monster
    Uptime
    60, plus 10 per unindexed request
    Latency
    8,400 ms and rising
    Threat Level
    ★★★☆☆

    Lore

    The Slow Query Slime starts out cute. A little blob, a few hundred rows, nothing to worry about. But every time it’s forced to read the whole table to find one record, it absorbs the effort and grows. A year later it fills the entire Database Depths, and every page load has to wade through it. Visitors start to wonder if the site is down. It isn’t. It’s just thinking.

    How to defeat it

    Add an Index. The Slime can’t grow if the database already knows exactly where to look. Database Wizards wearing the Index Amulet deal double damage here.

    Real-world tip: A slow query is a database request that takes too long, often because the database has to scan every row instead of jumping straight to the right ones. An index works like a book’s index and lets MySQL find rows quickly. Tools such as the Query Monitor plugin or MySQL’s EXPLAIN show which queries are slow and whether they use an index. Common WordPress causes are huge autoloaded options and searches on unindexed post meta.

  • The Deadlock Hydra

    The Deadlock Hydra

    Layer
    3. The Database Depths
    Type
    Layer Boss
    Uptime
    450 per head
    Latency
    ∞ (each head is waiting for the other)
    Threat Level
    ★★★★☆

    Lore

    The Deadlock Hydra has two heads, and both are extremely polite. The left head holds the orders table and won’t let go until the right head releases inventory. The right head holds inventory and won’t let go until the left head releases orders. “After you,” says one. “No, after you,” says the other. They have been saying this since 2019. Meanwhile, every request in the Realm queues up behind them.

    How to defeat it

    Kill one transaction so the other can finish. Sever one head and the other immediately completes its work and wanders off, satisfied.

    Real-world tip: A deadlock happens when two database transactions each lock something the other needs, so neither can continue. MySQL usually detects this and cancels one of them automatically, and the app should simply retry it. Frequent deadlocks point to code that locks tables in different orders or holds transactions open too long. Keeping transactions short and always locking in the same order prevents most of them.