Posted on

sodoku, or… now we can do everything in stored procedures!

Stored Procedures are a useful -but much abused- feature. Why abused? Well, sometimes it just doesn’t make any sense to put certain functionality into the database server.

A key positive is that business logic can be handled and enforced inside your RDBMS. Good! But something to also consider in the real world is the fact that you generally have more web or application servers than database servers. So for scaling, loading the database servers more can be an inefficient use of resources. It can make more sense to spread such tasks across the web/app servers. Of course it’s not a black&white story. Like any other tool, it has its positives and drawbacks and it should be used appropriately.

So, about doing weird things in SQL… Per-Erik Martin, the MySQL developer who led the implementation of stored procedures in MySQL 5.0, has written the following. It’s an SQL implementation of a sodoku puzzle solver. Senseless, certainly 😉 but it can still be interesting to look at these things as examples of what is possible with SQL. Per-Erik’s own excuse:

A complete compile-pentium-valgrind-max build takes about 45 minutes on my not-too-fast machine, and the test run about 35 minutes. It’s not always possible to fill this time with something useful to do, so it can get a little boring at times…

The SQL program listing is a bit long, so I posted it in a message on the MySQL Stored Procedures forum.

Posted on