Professional Documents
Culture Documents
Everybody loves Top 10 lists, but for a database as complex as Oracle its hard to distill
performance tuning best practices into a single book, let alone a list of 10 tips.
Nevertheless, in this serious of ToadWorld articles Ill try my best to present the ten
performance tuning concepts that I consider most important when optimizing Oracle
database performance.
At the risk of giving away the ending, here are the top 10 ideas that Ill cover in this series:
1. Adopt a methodical and empirical approach
2. Design performance into your application architecture and code
3. Index wisely
4. Know your tools
5. Optimize the optimizer
6. Tune SQL and PL/SQL
7. Relieve database contention points
8. Optimize memory to reduce IO
9. Tune IO last but TUNE it!
10. Exploit and optimize RAC
The structure of this series will roughly follow the structure of my new book Oracle
Performance Survival Guide, which includes more detail on each of the concepts.
In this first installment well focus on the first three ideas.
Activity in each of these layers influences the demand placed on the subsequent layer. For
instance, if a SQL statement is submitted which somehow fails to exploit an index, it will
require an excessive number of logical reads, which in turn will increase contention and
eventually involve a lot of physical IO. Its tempting when you see a lot of IO or contention
to deal with the symptom directly by tuning the disk layout. However, if you sequence your
tuning efforts so as to work through the layers in order, then you have a much better
chance of fixing root causes and relieving performance at lower layers.
1.
Figure 2: An entity with subtypes can be implemented as one, two or three tables.
Denormalization
The normalized data model is be a good starting point, but we often want to introduce
redundant, repeating or otherwise non-normalized structures into the physical model to get
the best performance. For instance we might:
Replicate columns from one table in another to avoid joins.
Create summary tables to avoid expensive aggregate queries possibly using
materialized views
Vertically partition a table so that long, infrequently accessed columns are stored in a
separate table.
Remember, denormalization introduces the risk of data inconsistency and the overhead of
maintaining denormalized data can slow down transaction processing. Using triggers to
maintain denormalization is a good idea since it centralizes the logic.
Partitioning
Oracles partitioning option requires separate licensing, but offers many advantages:
Some queries may be able to work on a subset of partitions. This partition
elimination can reduce IO overhead.
Some parallel operations especially DML operations can be significantly faster
when partitioning is available.
Purging old data can sometimes be achieved by quickly dropping a partition instead
of laboriously deleting thousands or millions of rows.
Some forms of contention hot blocks and latches can be reduced by splitting up
the table across the multiple segments of a partitioned object.
Application Design
The way you structure your application code can have a big impact as well:
The most optimized SQL is the one you never send. Reduce the amount of SQL you
send to the database by caching frequently used data items in memory.
Reduce parsing by using bind variables.
Reduce network round trips by using array fetch, array insert and stored procedures
where appropriate.
Bitmap indexes are useful to optimize queries in which multiple columns of low
cardinality are queried in combination. Unlike B*-tree indexes, multiple bitmap
indexes can be efficiently merged but can also increase lock contention.
Index design
Index design often involves constructing the best set of concatenated indexes. A
concatenated index is simply an index comprising more than one column. Concatenated
indexes are more effective merging multiple single column indexes and a concatenated
index that contains all of the columns in the WHERE clause will typically be the best way to
optimize that WHERE clause.
If a concatenated index could only be used when all of its keys appeared in the WHERE
clause, then concatenated indexes would probably be of pretty limited use. Luckily, a
concatenated index can be used effectively providing any of the initial or leading columns
are used.
The more columns in the concatenated index, the more effective it is likely to be. You can
even add columns from the SELECT list so that the query can be resolved by the index
alone. Figure 3 shows how the IO is reduced as columns are added to the concatenated
index for a query like this:
SELECT cust_id
FROM sh.customers c
WHERE cust_first_name = 'Connor'
AND cust_last_name = 'Bishop'
AND cust_year_of_birth = 1976;
Remember, every index adds overhead to DML operations, so only add an index if you are
Figure 4 The effect of adding indexes to the performance of a 1,000 row delete.
Coming up....
In the next installment of this series, well look at tools of the trade,
maximizing the Oracle optimizer and SQL/PLSQL tuning considerations.
Guy Harrison is a Director of Research and Development at Quest
Software, and has over 20 years experience in application and database
administration, performance tuning and software development. Guy is the
author of Oracle Performance Survival Guide (Prentice Hall, 2009) and
MySQL Stored Procedure Programming (OReilly with Steven Feuerstein) as
well as other books, articles and presentations on database technology. Guy is the architect
of Quest's Spotlight family of diagnostic products and has contributed to the development
of other Quest products, such as Toad. Guy can be found on the Internet at
file:///C:/Documents%20and%20Settings/shilker/My%20Documents/Biz%20Summaries/To
ad%20World/Experts/Guy%20Harrison/TopTen-1/www.guyharrison.net, on email at
guy.harrison@quest.com and is @guyharrison on twitter.