Skip to Content
Refactoring SQL Applications
book

Refactoring SQL Applications

by Stephane Faroult, Pascal L'Hermite
August 2008
Intermediate to advanced content levelIntermediate to advanced
298 pages
9h 22m
English
O'Reilly Media, Inc.
Content preview from Refactoring SQL Applications

Chapter 5. Statement Refactoring

The problem for us was to move forward to a decisive victory, or our cause was lost.

—Ulysses S. Grant (1822–1885)

Personal Memoirs, Chapter XXXVII

EVEN IF THERE IS OFTEN STILL ROOM FOR IMPROVEMENT WHEN ALL QUERIES HAVE BEEN “TUNED TO death,” as you saw in Chapter 1 (and as I will further demonstrate in the next few chapters), when a big, bad query flagrantly kills performance, improving that query has a tremendous psychological effect. If you want to be viewed with awe, it is usually better to improve a killer query than to humbly ensure that the system will be able to scale up in the next few months.

Although optimizers are supposed to turn a poorly expressed statement into efficient data handling, sometimes things go wrong, even when the indexing is sane and all the relevant information is available to the optimizer. You know how it is: even if the optimizer does a good job 99 times out of 100, it is the botched attempt that everyone will notice. Assuming once again that proper statistics are available to the optimizer, failure to perform well usually results from one of the following:

  • An optimizer bug (it happens!)

  • A query that is so complex that the optimizer tried, in the limited time it grants itself, only a small number of rewrites compared to the large number of possible combinations, and failed to find the best path in the process

I’d like to point out that optimizer bugs are most commonly encountered in situations of almost inextricable complexity, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

RESTful Java Web Services - Third Edition

RESTful Java Web Services - Third Edition

Balachandar Bogunuva Mohanram
Modernizing Enterprise Java

Modernizing Enterprise Java

Markus Eisele, Natale Vinto
Ultra-Fast ASP.NET 4.5

Ultra-Fast ASP.NET 4.5

Richard Kiessig

Publisher Resources

ISBN: 9780596514976Supplemental ContentErrata Page