很
多应用开发人员、特别是技术大拿、喜欢通过 HINT 强制Oracle CBO按自己的意志选择执行计划
Rocky 窃以为、这种策略在某种程度上其实是把双刃剑
使用 Hint 指定 Index 的时候需要慎重、如果不合适或者无效、可能画蛇添足、效率更低
Rocky 窃以为、这种策略在某种程度上其实是把双刃剑
使用 Hint 指定 Index 的时候需要慎重、如果不合适或者无效、可能画蛇添足、效率更低
摘自官方文档:
If the INDEX hint specifies no indexes, then the optimizer considers the cost of a scan on each available index on the table and
then performs the index scan with the lowest cost. The database can also choose to scan multiple indexes and merge the results,
if such an access path has the lowest cost. The optimizer does not consider a full table scan.
如果我们使用 HINT 指定了一个无效的 Index、CBO 会扫描表中所有可以使用的 Index
然后选择 cost 最小的 Index 或者复合索引、而不会选择全表扫描
测试:
① 创建一个表、