[bbk5307]第76集 第9章 -数据库性能维护 03
/*
Oracle optimizer 执行选择方式原理分析
*/
select * from emp where empno=7369;
oracle在执行查询计划的时候,并不是说要执行一次全表扫描和一次索引扫描之后,来决定到底是走哪一条路?而是通过数据字典里的统计数据信息,来分析判断到底是走那一条执行计划.
|-full table
|-index scan
data_table---> num_rows(10000)-1/10000
num_rows(10000)-1/2
SQL> create table emp1 as select * from emp; Table created. SQL> select table_name,num_rows from user_tables; TABLE_NAME NUM_ROWS ------------------------------ ---------- C_DEPT 0 C_EMP 0 T 107 M 3 EMP 107 DEPT 115 LOG 1249 LOG_LW 1438 EMP1 9 rows selected. SQL> select count(*) from emp1; COUNT(*) ---------- 107 SQL> analyze table emp1 compute statistics; Table analyzed. SQL> select table_name,num_rows from user_tables; TABLE_NAME NUM_ROWS ------------------------------ ---------- C_DEPT 0 C_EMP 0 T 107 M 3 EMP 107 DEPT 115 LOG 1249 LOG_LW 1438 EMP1 107 9 rows selected.
收集统计信息命令
analyze table emp1 compute statistics;
有关表的统计信息:dba_tables
有关索引的统计信息:dba_indexes
有关列的统计信息:dba_tab_col_statistics
oracle 10g-11g之后的版本可以分析oracle本身对象的统计指标信息,以及操作系统的通知指标信息,从而能够给我们提供更好的执行计划.
Optimizer Statistics Collection
- SQL performance tuning:Depends on collection of accurate statistics
- Optimizer statistics:
- -Object statistics
- -Operating system statistics
- Ways to collect statistics:
- -Automatically:Automatic Maintenance Tasks
- -Manually:DBMS_STATS package
- -By setting database initialization parameters
- -By importing statistics from another database