Indexes I forget to add

    December 18, 20244 blocks

    Foreign keys are not indexed by default

    In Postgres, declaring a foreign key does not create an index on the referencing column. Joins and cascading deletes get slow without one.

    CREATE INDEX ON orders (customer_id);
    Measure with EXPLAIN ANALYZE before and after — don't guess.