in reply to Re: Re (tilly) 4: How NOT to do it
in thread How NOT to do it

Sorry for being slow getting back, I have been offline.

The answer is that the database is supposed to figure out exactly what the SQL is supposed to do, and then come up with a very efficient way to do that. With a Turing-complete language it is impossible to answer detailed questions about arbitrary code, and is difficult to answer them even for normal code.

Sure, optimizers can speed up code. But in a normal language they can't recognize a bad algorithm and rewrite it with a more efficient one. But SQL routinely is optimized to be using algorithms which are far better than any that the developer would have thought up.

SQL could not do this if the developer had, for instance, the freedom to write a series of nested loops with possibly relevant side-effects and a difficult to discern purpose.