[bbk2345] 第50集 - Chapter 12-Optimizing Sore Perations(05)
Using System Statistics
- System statistics enable the CBO to use CPU and I/O characteristics.
- System statistics must be gathered on a regular basis;this does not invalidate cached plans.
- Gathering system statistics equals analyzing system activity for a specified period of time.
所有的System Statistics 信息,都将作为CBO决策的依据.
Gathering System statistics
Procedures of the dbms_stats package used to collect system statistics:
- gather_system_stats
- set_system_stats
- get_system_stats
Manual Gathering
- Start manual system statistics collection in the data dictionary:
EXECUTE dbms_stats.gather_system_stats(gathering_mode => 'START');
- Genernate the workload
- End system statistics collection:
EXECUTE dbms_stats.gather_system_stats(gathering_mode => 'STOP');
Automatic Gathering
Collect statistics for OLTP:
EXECUTE dbms_stats.gather_system_stats(interval => 120,stattab => 'mystats',statid => 'OLTP');
Collect statistics for OLAP:
EXECUTE dbms_stats.gather_system_stats(interval => 120,stattab => 'mystats',statid => 'OLAP');
Import System Statistics
For daytime(OLTP):
EXECUTE dbms_stats.import_system_stats(stattab => 'mystats',statid => 'OLTP' );
For nighttime(OLAP):
EXECUTE dbms_stats.import_system_stats(stattab => 'mystats',statid => 'OLAP');
Copy Statistics Between DBs
Example
CREATE TABLE
SQL> exec dbms_stats.create_stat_table('HR','MYSTATS'); PL/SQL procedure successfully completed. SQL> desc mystats; Name Null? Type ----------------------------------------- -------- ---------------------------- STATID VARCHAR2(30) TYPE CHAR(1) VERSION NUMBER FLAGS NUMBER C1 VARCHAR2(30) C2 VARCHAR2(30) C3 VARCHAR2(30) C4 VARCHAR2(30) C5 VARCHAR2(30) N1 NUMBER N2 NUMBER N3 NUMBER N4 NUMBER N5 NUMBER N6 NUMBER N7 NUMBER N8 NUMBER N9 NUMBER N10 NUMBER N11 NUMBER N12 NUMBER D1 DATE R1 RAW(32) R2 RAW(32) CH1 VARCHAR2(1000) CL1 CLOB
Summary
In this lesson,you should have learned how to:
- Collect system statistics
- Collect statistics on indexes and tables
- Describe the use of histograms(主要用在column statistics上面.)
- Copy statistics between database(主要应用在将生产库的真实环境数据,转移到测试环境下,安全有效的测试系统)
- Determine usage of indexes(此部分,没有做任何讲解)