Beruflich Dokumente
Kultur Dokumente
Oracle Articles
New Oracle Articles
Create a proper development environment for
Oracle SQL
Oracle Training
In order to provide a consistent SQL execution environment in Oracle there are a
Oracle Tips
number of environmental issues that should be addressed. By ignoring these issues
Oracle Forum you invite instability, acknowledged by ever-changing SQL execution plans,
Class Catalog resulting in poor database query performance.
Using the Oracle dbms_stats package, provides much better optimizer statistics than
the older ANALYZE TABLE methodology. It is also rumored that future versions of
the optimizer will require that statistics be collected using dbms_stats. The Oracle9i
version of dbms_stats provides parameters that allow Oracle to determine which
objects require new statistics and the percentage of data to be analyzed.
execute dbms_stats.gather_schema_stats (
ownname => 'SCOTT',
estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt => 'FOR ALL COLUMNS SIZE AUTO',
degree => DBMS_STATS.DEFAULT_DEGREE,
cascade => TRUE);
Highly volatile tablesIn these environments, the size of tables and the
characteristics of index columns change dramatically. If, for example, you
have a table that has 100 rows one day and 100,000 rows a few days later, then
you probably should consider a periodic reanalysis of the schema statistics.
It's important to emphasize the fact that changing the CBO parameters in a
production database environment, without careful evaluation, can be risky. A single
parameter change could have an adverse influence on the performance of the entire
database. Do not change vital initialization parameters such as optimizer_mode,
optimizer_index_caching, and optimizer_index_cost_adj on a production system
without careful assessment and testing.
Require SQL tuning prior to implementation
Once you realize how crucial efficient execution plans are to query performance, it is
amazing to discover how many Oracle installations don't even consider reviewing
the execution plans of their production queries. Administrators of those installations
may incorrectly assume that the CBO is intelligent enough to always provide the
optimal execution plan, no matter how the SQL is coded.
Listing A
-- Form one using non-correlated subquery
select
book_title
from
book
where
book_key not in (select book_key from sales);
Execution Plan
---------------------------------------------------------
-
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1
Bytes=64)
1 0
FILTER
2 1 TABLE ACCESS (FULL) OF 'BOOK' (Cost=1 Card=1
Bytes=64)
3 1 TABLE ACCESS (FULL) OF 'SALES' (Cost=1 Card=5
Bytes=25)
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=100
Bytes=8200)
1 0 FILTER
2 1 FILTER
3 2 HASH JOIN
(OUTER)
4 3 TABLE ACCESS (FULL) OF 'BOOK' (Cost=1 Card=20 Bytes=1280)
5 3 TABLE ACCESS (FULL) OF 'SALES' (Cost=1 Card=100
Bytes=1800)
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1
Bytes=59)
1 0
FILTER
2 1 TABLE ACCESS (FULL) OF 'BOOK' (Cost=1 Card=1
Bytes=59)
3 1
FILTER
4 3 NESTED LOOPS (Cost=6 Card=1
Bytes=82)
5 4 TABLE ACCESS (FULL) OF 'SALES' (Cost=1 Card=5
Bytes=90)
6 4 TABLE ACCESS (BY INDEX ROWID) OF 'BOOK' (Cost=1 Card=1)
7 6 INDEX (UNIQUE SCAN) OF 'PK_BOOK' (UNIQUE)
From these examples, you observe that the proper coding of a query has a dramatic
influence on its execution plan. Shrewd developers know the most efficient way to
code SQL to produce optimal execution plans. Perceptively managed Oracle
installations provide training to their developers to enhance their knowledge of the
formulation of efficient queries.
Some suggested techniques for raising the awareness of the importance of SQL
tuning and to assist developers in tuning their queries include the following:
Optimal execution
Efficient SQL coding is important in the creation of an optimal execution plan by the
CBO. Maintaining a stable SQL environment using the guidelines presented in this
article ensures that the SQL you create, tune, and test in your test environment will
perform exactly the same when migrated into production.
Burleson Consulting
The Oracle of Database Support