How to kill your server with a single SQL query

SQL can be a dangerous animal. Usually, when you write a bad query, it's no big deal. But occasionally you might encouter the cartesian join

By JC

SQL can be a dangerous animal if you’re not careful or don’t know what you’re doing. Usually, when you write a bad query it simply fails or gives the wrong results. But occasionally you may hit the jackpot and take your server down by utilizing a Cartesian Join

All you have to do is join one table to another table without a where clause (or a useless but valid one). The more tables you have, and the bigger the tables are, the more CPU intensive it is — you’re joining everything to everything. On rare, rare occasions, this may be something you wish to do, but it’s usually a mistake. And on a big enough dataset, you can watch the server thrash until it dies (well, ok, until it needs some processes killed or a swift reboot).

Have something to tell us about this article?
Let us know

or Comment Below

LOGIN to Comment
LOGIN to Comment

Got a tip?

Let us know