今天听了B2C 陈立同学的CBO体系结构的分享,收益颇多。 够我消化好一阵子了,很多东西是在不断的摸索中积累起来的。 向大牛们学习!
基于规则的优化器
1: 通过rowid访问单笔记录
2: Single Row by Cluster Join
3: Single Row by Hash Cluster Key with Unique or Primary Key
4: 通过唯一索引或主键访问单笔记录
5: Clustered Join
6: Hash Cluster Key
7: Indexed Cluster Key
8: 复合索引扫描
9: 单列索引扫描
10: 索引列上的闭区间搜索
11: 索引列上的开区间搜索
12: 排序归并连接
13: 索引列的MAX和MIN
14: 索引列排序
15: 全表扫描
CBO误区
不同SQL文本的Cost是不可比较的
统计信息就是指柱状图
执行计划突然错误, 分析柱状图就可以解决所有问题
帮定变量可以减少硬解析, 任何时候都应该使用它
/*+NO_MERGE*/是不使用归并连接
单表访问路径
全表扫描(Full Table Scan)
Cost ≈ Blocks / db_block_multiblock_read_count
索引范围扫描(Index Range Scan)
Cost =
BLevel +
Index Selective × Leaf Blocks
[ + Table Selective × Clustering Factor]
[ - 1]
索引快速全扫描(Fast Full Index Scan)
索引全扫描(Index Full Scan)
Cost ≈ Leaf Blocks / db_block_multiblock_read_count
Column1 = value1
1/distinct_value
Column1 > value1
Column1 < value1
Function(C1) operator value1
对于等于是固定的1%
对于其他的是固定的5%
重要的统计变量
Table
--Blocks 决定全表扫描成本
--Num_rows 决定单表访问的输出结果集基数
Index
--Leaf_blocks 决定索引全扫描/范围扫描成本
--Blevel 决定索引唯一扫描成本
--Clustering_factor 决定索引访问表成本
Column
--Num_distinct 无柱状图时使用 = :1 时决定选择率
--Density 有柱状图时使用 =:1 时决定选择率
--Low_value & High_value 使用硬编码时决定选择率
--EOF--
This work is licensed under a CC A-S 4.0 International License.