|
|
|
|
|
|
After completing this lesson, you should be able
to do the following: |
|
Identify the role of the DBA in application
tuning |
|
Use optimizer modes to enhance SQL statement
performance |
|
Manage stored outlines to store execution paths
as a series of hints |
|
|
|
|
|
Use the available data access methods to tune
the physical design of the database |
|
Identify the demands of online transaction
processing (OLTP) systems |
|
Identify the demands of decision support systems
(DSS) |
|
Reconfigure systems on a temporary basis for
particular needs |
|
|
|
|
|
Application tuning is the most important part of
tuning. |
|
DBAs may not be directly involved in application
tuning. |
|
DBAs must be familiar with the impact that
poorly written SQL statements can have upon database performance. |
|
|
|
|
|
EXPLAIN PLAN |
|
SQL Trace and TKPROF |
|
SQL*Plus AUTOTRACE |
|
Oracle SQL Analyze |
|
|
|
|
|
Can be used without tracing |
|
To use the explain plan: |
|
1. Create PLAN_TABLE with utlxplan.sql. |
|
2. Run the EXPLAIN PLAN SQL command. |
|
3. Query PLAN_TABLE to display the execution
plans. |
|
|
|
|
|
1. Set the initialization parameters. |
|
2. Invoke SQL Trace. |
|
3. Run the application. |
|
4. Turn off SQL Trace. |
|
5. Format the trace file with TKPROF. |
|
6. Interpret the output. |
|
|
|
|
|
Instance level:
SQL_TRACE =
{TRUE|FALSE} |
|
Session level: |
|
|
|
|
|
|
|
Count: Number of execution calls |
|
CPU: CPU seconds used |
|
Elapsed: Total elapsed time |
|
Disk: Physical reads |
|
Query: Logical reads for consistent read |
|
Current: Logical reads in current mode |
|
Rows: Rows processed |
|
|
|
|
|
Create PLAN_TABLE |
|
Run plustrce.sql from the ORACLE_HOME/sqlplus/admin
directory |
|
AUTOTRACE syntax: |
|
|
|
|
|
|
Rule-based: |
|
Uses a ranking system |
|
Syntax- and data dictionary–driven |
|
Cost-based: |
|
Chooses least-cost path |
|
Statistics-driven |
|
|
|
|
|
|
Instance level: |
|
optimizer_mode =
{choose|rule|first_rows|all_rows} |
|
Session level: |
|
alter session set optimizer_mode =
{choose|rule|first_rows|all_rows} |
|
Statement level: Using hints |
|
|
|
|
|
|
Use the ANALYZE command to collect or delete
statistics. |
|
Use the DBMS_STATS package: |
|
GATHER_TABLE_STATS |
|
GATHER_INDEX_STATS |
|
GATHER_SCHEMA_STATS |
|
GATHER_DATABASE_STATS |
|
|
|
|
|
Number of rows |
|
Number of blocks and empty blocks |
|
Average available free space |
|
Number of chained or migrated rows |
|
Average row length |
|
Last ANALYZE date and sample size |
|
Data dictionary view: DBA_TABLES |
|
|
|
|
|
Index level (height) |
|
Number of leaf blocks and distinct keys |
|
Average number of leaf blocks per key |
|
Average number of data blocks per key |
|
Number of index entries |
|
Clustering factor |
|
Data dictionary view: DBA_INDEXES |
|
|
|
|
|
Number of distinct values |
|
Lowest value, highest value |
|
Last ANALYZE date and sample size |
|
Data dictionary view: USER_TAB_COL_STATISTICS |
|
|
|
|
|
Describe the data distribution of a particular
column in more detail |
|
Better predicate selectivity estimates for
unevenly distributed data |
|
Create histograms with
ANALYZE TABLE
... FOR COLUMNS ... |
|
Data dictionary view: DBA_HISTOGRAMS |
|
|
|
|
|
|
|
|
|
Allows applications to force the use of a
desired SQL access path |
|
Maintains
consistent execution path through database changes |
|
Is implemented using a stored outline consisting
of hints |
|
|
|
|
|
|
SQL statement text must match |
|
Plans are maintained through: |
|
New Oracle versions |
|
New statistics on objects |
|
Initialization parameter changes |
|
Database reorganization |
|
Schema changes |
|
|
|
|
|
|
|
Set the USE_STORED_OUTLINES parameter to TRUE or
to a category name |
|
|
|
|
|
|
|
Both CREATE_STORED_OUTLINES and USE_STORED_OUTLINES
can be set at the instance or session level |
|
|
|
|
|
|
Use the OUTLN_PKG package to: |
|
Drop outlines or categories of outlines |
|
Rename categories |
|
Use the ALTER OUTLINE command to: |
|
Rename an outline |
|
Rebuild an outline |
|
Change the category of an outline |
|
Outlines are stored in OUTLN schema |
|
|
|
|
|
To enhance performance, you can use the
following data access methods: |
|
Indexes (B-tree, bitmap, reverse key) |
|
Index-organized tables |
|
Clusters |
|
Histograms |
|
Materialized views |
|
|
|
|
|
|
|
|
|
Used for low-cardinality columns |
|
Good for multiple predicates |
|
Use minimal storage space |
|
Best for read-only systems |
|
Good for very large tables |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Faster key-based access to table data |
|
Reduced storage requirements |
|
Secondary indexes and logical ROWIDs |
|
Main restrictions: |
|
Must have a primary key |
|
Cannot use unique constraints |
|
Cannot be clustered |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Are instantiations of a SQL query |
|
Can be used for query rewrites |
|
Refresh types: |
|
Complete or fast |
|
Force or never |
|
Refresh modes: |
|
Manual |
|
Automated (synchronous or asynchronous) |
|
|
|
|
Refresh-specific MVs: |
|
MVs based on one or more base tables: |
|
All MVs due for refresh: |
|
|
|
|
|
To use MVs instead of the base tables, a query
must be rewritten. |
|
Query rewrites are transparent and do not
require any special privileges on the MV. |
|
MVs can be enabled or disabled for query
rewrites. |
|
|
|
|
|
The initialization parameter
QUERY_REWRITE_ENABLED must be set to TRUE. |
|
The QUERY REWRITE privilege allows users to
enable materialized views. |
|
The DBMS_OLAP package has options to use
materialized views. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
High throughput, insert- and update-intensive |
|
Large, continuously growing data volume |
|
Concurrent access by many users |
|
Tuning goals: |
|
Availability |
|
Speed |
|
Concurrency |
|
Recoverability |
|
|
|
|
|
|
Explicit space allocation |
|
Indexes: |
|
Not too many (prefer B-tree to bitmap) |
|
Reverse key for sequence columns |
|
Rebuilt regularly |
|
Clusters for tables in join queries: |
|
Index clusters for growing tables |
|
Hash clusters for stable tables |
|
|
|
|
|
Short transactions do not require big rollback
segments; multiple rollback segments prevent contention. |
|
A large MINEXTENTS value is required. |
|
|
|
|
|
Use database constraints instead of application
code. |
|
Make sure that code is shared. |
|
Use bind variables rather than literals for
optimally shared SQL. |
|
|
|
|
|
|
Queries on large amounts of data |
|
Heavy use of full table scans |
|
Tuning goals: |
|
Fast response time |
|
Accuracy |
|
Availability |
|
Parallel Query is particularly designed
for DSS environments |
|
|
|
|
|
Storage allocation: |
|
Set db_block_size and db_file_multiblock_read_count carefully. |
|
Ensure that extent sizes are multiples of this
parameter value. |
|
Run ANALYZE regularly. |
|
|
|
|
|
|
Evaluate the need for indexes: |
|
Use bitmap indexes when possible. |
|
Use index-organized tables for (range) retrieval
by PK. |
|
Generate histograms for indexed columns that are
distributed nonuniformly. |
|
Clustering: Consider hash clusters for
performance access. |
|
|
|
|
|
|
Parse time is less important. |
|
The execution plan must be optimal. |
|
Use the Parallel Query feature. |
|
Tune carefully, using hints if appropriate. |
|
Test on realistic amounts of data. |
|
Consider using PL/SQL functions to code logic
into queries. |
|
Bind variables are problematic. |
|
|
|
|
|
Combination of OLTP and DSS |
|
Hybrid systems rely on several configurations |
|
|
|
|
|
|
|
|
Memory use: |
|
SHARED_POOL_SIZE |
|
LARGE_POOL_SIZE |
|
DB_BLOCK_BUFFERS |
|
SORT_AREA_SIZE |
|
Parallel Query: Reconfigure parameters for DSS |
|
|
|
|
|
|
Online rollback segments: |
|
More small ones during the day |
|
Fewer, large ones at night |
|
Multithreaded server (MTS):
For peak-time use, not for DSS |
|
|
|
|
|
In this lesson, you should have learned that: |
|
Application tuning often results in the greatest
performance benefits. |
|
You tune CBO with parameters and hints. |
|
You use stored outlines for plan stability. |
|
You should apply available data access methods
appropriately. |
|
|
|
|
|
For OLTP, try to reach the following goals: |
|
Immediate access to small amounts of data
(indexing, hashing) |
|
Immediate concurrent access to transaction
tables |
|
Shared code to cut down parse time |
|
No space allocation during peak hours |
|
|
|
|
|
For DSS, try to reach the following goals: |
|
Data tightly packed into large blocks |
|
Careful tuning of queries |
|
Histograms generation |
|
Query rewrites using materialized views and
dimensions |
|
Well-configured Parallel Query support |
|