39

Optimizing SQL

There is no set of rules for writing code that will take the best advantage of every query optimizer on every SQL product every time. The query optimizers depend on the underlying architecture and are simply too different for many universal rules; however, we can make a few general statements. Just remember that you have to test code. What would improve performance in one SQL implementation might not do anything at all in another or make the performance worse. Even worse, the next release of the same SQL can perform differently.

There are two kinds of optimizers: cost-based and rule-based. A rule-based optimizer (such as Oracle before Version 7.0) will parse a query and execute it in the order in which it was written, perhaps ...

Get Joe Celko's SQL for Smarties, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.