Note to self: don’t do this

ERROR 1116 (HY000): Too many tables; MySQL can only use 61 tables in a join

If you ever run into this MySQL error, something has gone badly wrong with your database schema. In this case, the database had no foreign key constraints, and I was trying to build a DELETE query that cascaded across ~230 tables. Not pretty at all.

It doesn’t help that there’s no consistency in key names - id, clientid, client, fkClient - all refer to the same foreign key in different tables.

Update: After a few false starts, I’ve given up on doing the deletes by hand; instead I’m going through the database creating the foreign key constraints that should have been there in the first place. It’s the same amount of work, I end up with a slightly saner database, and doing the delete becomes a simple delete clientid, which cascades through the rest of the tables removing related data.