The BDBAFH Chronicles #006: The Unindexed Foreign Key Cascade
A backend developer designed a schema with 60 tables linked through foreign keys, but omitted an index on every single foreign key column. Every DELETE operation on a parent table forced a…
Incident #006 of the BDBAFH Chronicles: The Unindexed Foreign Key Cascade. Dark-humor fiction: no real people, companies or incidents.

A backend developer designed a schema with 60 tables linked through foreign keys, but omitted an index on every single foreign key column. Every DELETE operation on a parent table forced a cascading full table scan across all 60 child tables.
A simple user deletion held an exclusive lock on the database for 3 minutes.
I ran pg_stat_user_tables to identify the bottleneck. Instead of silently fixing it on dev, I added a trigger on his staging environment: every time an unindexed FK query triggered a sequential scan, his machine’s speaker played the sound of a foghorn and printed a real-time estimation of wasted CPU clock cycles to his terminal.
He added all 60 indexes before lunch.
The BDBAFH Chronicles are works of dark-humor fiction inspired by the Bastard Operator From Hell and The Daily WTF. Names, companies and incidents are invented, and any resemblance to real ones is coincidental. Commands and outputs are illustrative and untested: do not run them on a system you care about.