Tuning 12 manage statistics

这个 stattistics 对解析 sql 时的优化器有很重要的作用, 优化器是基于 statistics 来进行优化的.

image

image

image

image

desc dbms_stats 包也可以 desc (早期使用 analyze table 之类的)

image

实验:

我们创建一个新表在HR这个 schema 里, 比如 create table t ( id int, name varchar2(10));

创建完以后, 我们插入 3 条记录. 并 commit;

然后我们查询 DBA_TABLES 这个数据字典, 注意, 虽然我们能够查询到这个数据字典中包含 t 这个table, 但是这个table有多少行和多少block, 这些信息是空的, 因为这个表我们刚刚创建, 还没有更新信息, 所以我们使用:

exec dbms_stats.gather_table_stats(‘hr’,’t’);  -- 这样就搜集了 hr这个用户下 t 这个表的信息

然后我们在去看 dba_tables 中的内容, 这时候 这个table有多少行和多少block就显示出来了.

那么这些 statistics 信息对优化器有什么作用呢, 比如刚刚我们创建的表, statistics显示只有3条记录, 那么优化器基于这个信息就可以放弃索引, 直接全表扫描.

image

以上这些表, 都是10g 以后才有的.

image

image

image

image

image

image

image

就是默认的 oracle 自己运行的动态的更新 statistics 信息.

image

image

image

image

image

image

image

image

image

image

原文地址:https://www.cnblogs.com/moveofgod/p/3638526.html