01.09.2016 Views

Beginning Oracle Database 11g Administration From Novice to Professional

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 17<br />

SQL Tuning<br />

Every limbo boy and girl<br />

All around the limbo world<br />

Gonna do the limbo rock<br />

All around the limbo clock<br />

—“Limbo Rock,” recorded by Chubby Checker in 1962<br />

()<br />

Perhaps the most complex problem in database administration is SQL tuning, and it<br />

may not be a coincidence that I left it for the very end. The paucity of books devoted <strong>to</strong><br />

SQL tuning is perhaps further evidence of the difficulty of the <strong>to</strong>pic.<br />

The only way <strong>to</strong> interact with <strong>Oracle</strong>, <strong>to</strong> retrieve data, <strong>to</strong> change data, <strong>to</strong> administer<br />

the database, is SQL. <strong>Oracle</strong> itself uses SQL <strong>to</strong> perform all the work that it does behind the<br />

scenes. SQL performance is therefore the key <strong>to</strong> database performance; all database performance<br />

problems are really SQL performance problems even if they express themselves<br />

as contention for resources.<br />

In this chapter, I will present some of the causes of inefficient SQL and some of the<br />

common techniques of making SQL more efficient, but we will spend most of our time<br />

working through a case study. I will present a fairly typical SQL statement and improve it in<br />

stages until it hits the theoretical maximum level of performance that is possible <strong>to</strong> achieve.<br />

Defining Efficiency<br />

The efficiency of an SQL statement is measured by the amount of computing resources<br />

such as CPU cycles used in producing the output. Reducing the consumption of resources<br />

is the goal of SQL tuning. Elapsed time is not a good measure of the efficiency of an SQL<br />

statement because it is not always proportional <strong>to</strong> the amount of resources consumed.<br />

For example, contention for CPU cycles and disk I/O causes execution delays. The number<br />

of logical read operations is a better way <strong>to</strong> measure the consumption of computing<br />

resources because it is directly proportional <strong>to</strong> the amount of resources consumed—the<br />

fewer the number of logical read operations, the less CPU consumption.<br />

381

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!