📢
24

My first MySQL query crashed the whole dev database yesterday

So I'm in this online class, 3 weeks into learning SQL. I thought I was being smart writing a JOIN across like 4 tables to find customer orders with specific products. Ran it without a WHERE clause by accident. The thing pulled 800,000 rows and locked up the database for everyone in my cohort for 15 minutes. Instructor had to kill the process from his end. How do you recover from making a dumb rookie mistake like that without feeling like everyone's watching you?
2 comments

Log in to join the discussion

Log In
2 Comments
jamieperez
jamieperez19h ago
A four table join with no WHERE clause is called a cartesian product, not exactly a JOIN.
8
park.adam
park.adam18h ago
Did your instructor give you any tips on using EXPLAIN before running queries? That saved me after I did basically the same thing on a shared dev server a few years back. A cartesian product on big tables is brutal, trust me I know. The best recovery is just owning it with your cohort and asking if anyone wants to pair up on query testing next time. Everyone in that class has made or will make a similar mistake, databases are unforgiving that way. Just make it a habit to always type WHERE and LIMIT 100 before you even write the rest of the query.
5