索引列等值条件 :
ix_sel
= 1/num_distinct 或 density
ix_sel_with_filters
= 0.01
索引列范围条件 :
ix_sel
= 0.009
ix_sel_with_filters
= 0.05
注意 :可能导致回表后的cardinality估算行数大于索引扫描行数
无peeking情况 :
sel
= 0.009
ix_sel
= 0.009
ix_sel_with_filters
= 0.05
索引列多个范围AND条件 :
ix_sel
= 0.009/2 = 0.0045
ix_sel_with_filters
= (sel_1)*
(sel_2) = 0.05*
0.05
索引列OR条件 :
等值条件:1/num_distinct
范围条件:0.009
回表
ix_sel_with_filters
= (sel_1)+(sel_2)-(sel_1*sel_2)
函数等值条件
:
sel
= 0.01
函数范围条件
:
sel
= 0.05
非索引列范围条件
:
sel
= 0.05
sel
=
ix_sel_with_filters
*
condition_filters
无额外条件:=
ix_sel_with_filters
回表非函数等值条件:max(1/num_distinct, density) * adjust_sel
回表函数等值条件:0.01
其他:0.05
有索引的等值条件 :
ix_sel
= 0.004
ix_sel_with_filters
= 0.01
无索引的等值条件
:
sel
= 0.01
(包括绑定变量无具体值、函数条件的等值查询)
非索引列范围查询
:
sel
= 0.05
索引列范围条件 :
ix_sel
= 0.009
ix_sel_with_filters
= 0.05
列无统计信息的<>条件
:
sel
= 5%
| 场景 | Oracle 默认选择率 | MySQL 默认选择率 |
|---|---|---|
| 等值条件 | 很小(0.004, 0.009等) | 较大(10%) |
| 范围条件(>,<) | 0.05(非索引) | 33% |
| LIKE条件 | 0.05 | 11% |
| BETWEEN条件 | 0.05 | 11% |
| 不等条件(<>) | 5% | 0.9 |
Oracle偏向索引 :
有索引的等值条件选择率很小(0.004, 0.009)
鼓励使用索引访问路径
MySQL默认选择率较大 :
可能导致全表扫描
需要建索引或收集直方图来改善
缺少动态采样、扩展统计信息等高级功能
绑定变量影响 :
Oracle在没有peeking时使用固定选择率
可能导致执行计划不稳定
多条件组合 :
AND条件:选择率相乘(独立假设)
OR条件:选择率相加再减去乘积
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7655508/viewspace-3146066/ ,如需转载,请注明出处,否则将追究法律责任。