Oracle使用Optimizer_mode参数来控制优化器的偏好,9i常用的几个参数有:first_rows,all_rows,first_rows_Nrule,choose等。而10g少了rulechoose

optimizer_mode =choose

这个是Oracle的默认值。采用这个值时,Oracle即可以采用基于规则RBO,也可以采用基于代价的CBO,到底使用那个值,取决于当前SQL的被访问的表中是不是有可以使用的统计信息。如果有多个被访问的表,其中有一个或多个有统计信息,那么Oralce会对没有统计信息的表进行采样统计(即不全部采样),统计完成后,使用基于代价的优化方法CBO。如果所有被访问的表都没有统计信息,Oracle就会采用基于规则的优化方法RBO

Optimizer_mode=First_rows

oracle 9i之后这一选项已经过时,出于向后兼容的目的保留了这一选项,该选项的作用在于寻找能够在最短的时间内返回结果集的第一行的执行计划。这一规则倾向于促使优化器使用索引访问路径,偶尔会出现非常不恰当的访问路径。

设置为这种CBO模式以后,SQL语句返回结果的速度会尽可能的快,而不管系统全部的查询是否会耗时较长或者耗系统资源过多。由于利用索引会使查询速度加快,所以first_rows 优化模式会在全表扫描上进行索引扫描。这种优化模式一般适合于一些OLTP系统,满足用户能够在较短时间内看到较小查询结果集的要求。

Optimizer_mode=all_rows

优化器将寻找能够在最短的时间内完成语句的执行计划。

设置为这种CBO模式以后,将保证消耗的所有计算资源最小,尽管有时查询结束以后没有结果返回。all_rows的优化模式更倾向于全表扫描,而不是全索引扫描和利用索引排序,因此这种优化模式适合于数据查看实时性不是那么强的数据仓库、决策支持系统和面向批处理的数据库(batch-oriented databases)等。

Optimizer_mode=first_rows_N

N的值可以为1101001000,优化器首先通过彻底分析第一个连接顺序来估计返回行的总数目。这样就可以知道查询可能获得的整个数据集的片段,并重新启动整个优化过程,其目标在于找到能够以最小的资源消耗返回整个数据片段的执行计划。

Oracle 9i 对一些预期返回结果集的数据量小的SQL语句优化模式进行了加强,增加了四个参数值:first_rows_1first_rows_10first_rows_100first_rows_1000CBO通过first_rows_n中的 n 值,决定了返回结果集数量的基数,我们可能仅仅需要查询结果集中的一部分,CBO就根据这样的n 值来决定是否使用索引扫描。

optimizer_mode = rule

基于规则的优化器模式,RBO,是早期Oracle版本使用过的一种优化模式。由于RBO不支持自1994Oracle版本的新特性,如bitmap indexestable partitionsfunction-based indexes等,所以在以后Oracle版本中已经不再更新RBO,并且也不推荐用户使用RBO这种优化模式了。

alter system set optimizer_mode=rule scope=both;

show parameter optimizer_mode

这是9i的文档:

CHOOSE

The optimizer chooses between a cost-based approach and a rule-based approach, depending

on whether statistics are available. This is the default value.

n If the data dictionary contains statistics for at least one of the accessed tables, then the

optimizer uses a cost-based approach and optimizes with a goal of best throughput.

n If the data dictionary contains only some statistics, then the cost-based approach is still

used, but the optimizer must guess the statistics for the subjects without any statistics.

This can result in suboptimal execution plans.

n If the data dictionary contains no statistics for any of the accessed tables, then the

optimizer uses a rule-based approach.

ALL_ROWS

The optimizer uses a cost-based approach for all SQL statements in the session regardless of

the presence of statistics and optimizes with a goal of best throughput (minimum resource use

to complete the entire statement).

FIRST_ROWS_n

The optimizer uses a cost-based approach, regardless of the presence of statistics, and

optimizes with a goal of best response time to return the first n number of rows; n can equal 1,

10, 100, or 1000.

FIRST_ROWS

The optimizer uses a mix of cost and heuristics to find a best plan for fast delivery of the first

few rows. Note: Using heuristics sometimes leads the CBO to generate a plan with a cost that is

significantly larger than the cost of a plan without applying the heuristic. FIRST_ROWS is

available for backward compatibility and plan stability.

RULE

The optimizer chooses a rule-based approach for all SQL statements regardless of the presence of statistics.

而在10g的文档中,我们看到值被减少到3个,而描述也不尽相同。

ALL_ROWS

The optimizer uses a cost-based approach for all SQL statements in the session regardless of the presence of statistics and optimizes with a goal of best throughput (minimum resource use to complete the entire statement). This is the default value.

FIRST_ROWS_n

The optimizer uses a cost-based approach, regardless of the presence of statistics, and optimizes with a goal of best response time to return the first n number of rows; n can equal 1, 10, 100,

or 1000.

FIRST_ROWS

The optimizer uses a mix of cost and heuristics to find a best plan for fast delivery of the first few rows. Note: Using heuristics sometimes leads the query optimizer to generate a plan with a cost that is significantly larger than the cost of a plan without applying the heuristic. FIRST_ROWS is

available for backward compatibility and plan stability; use FIRST_ROWS_n instead.

optimizer_mode相关推荐

  1. oracle optimizermode,Oracle OPTIMIZER_MODE参数

    Oracle 在执行SQL语句时,有两种优化方法:即基于规则的RBO和基于代价的CBO. 在SQL执教的时候,到底采用何种优化方法,就由Orac Oracle 在执行SQL语句时,有两种优化方法:即基 ...

  2. optimizer_mode优化器模式

    查询优化器最主要的工作就是接受输入的SQL以及各种环境参数.配置参数,生成合适的SQL执行计划(Execution Plan). Query Optimizer一共经历了两个历史阶段: RBO: Ru ...

  3. Mysql rbo和cbo_oracle的优化——RBO和CBO简介以及optimizer_mode参数说明

    最近对oracle的优化比较感兴趣,所以想跟大家分享一下学习经验. 在oracle中,sql语句优化分成RBO(Rule-Based Optimization)基于规则的优化和CBO(Cost-Bas ...

  4. oracle的mode,Oracle中使用optimizer_mode参数意义

    Oracle使用Optimizer_mode参数来控制优化器的偏好,9i常用的几个参数有:first_rows,all_rows,first_rows_N,rule ,choose等.而10g少了ru ...

  5. oracle 优化器 失效,oracle 优化器 不走索引原因

    SQL优化器简介 基于规则的优化器 .总是使用索引 .总是从驱动表开始(from子句最右边的表) .只有在不可避免的情况下,才使用全表扫描 .任何索引都可以 基于成本的优化器 .需要表.索引的统计资料 ...

  6. sap oracle 内存参数,ORACLE 25个需要深思熟虑重要的初始化参数

    此内容摘自 ORACLE 11gR2性能调整与优化一书,做为一个自己的笔记 1 MEMORY_TARGET : 这个初始化参数设定分配给PGA和SGA 的所有内存(11g 新参数).设置了MEMORY ...

  7. c 连接oracle的参数,[20210203]19c登录连接改变一些参数.txt

    [20210203]19c登录连接改变一些参数.txt --//昨天看了https://blog.dbi-services.com/19c-serverless-logon-trigger/,19c可 ...

  8. SQL 调优专题总结

    oracle 的优化器: oracle 有两种优化器:基于规则的优化器(rbo/rule based optimizer)和基于代价的优化器(cbo/cost based optimizer). 有时 ...

  9. PLSQL_性能优化系列04_Oracle Optimizer优化器

    2014-09-25 Created By BaoXinjian 一.摘要 1. Oracle优化器介绍 本文讲述了Oracle优化器的概念.工作原理和使用方法,兼顾了Oracle8i.9i以及最新的 ...

最新文章

  1. 数据库SQL Server 2019安装向导的“功能选择”详细说明(微软官方资料)
  2. 缩点+染色+DFS codeforce467D
  3. bst latex 最大作者数_latex 参考文献作者是三个以上时如何处理?
  4. Lambda表达式的省略模式【应用】
  5. Jar包转成Dll的方式(带嵌套的jar也能做) (转)
  6. HUD4035Maze
  7. 自由职业半年,我又滚回职场了...
  8. 排球计分程序重构(四)
  9. Java后台调用API的方法
  10. 将win10家庭版、教育版系统激活为win10专业版
  11. ddos源码 ntp_DDOS攻击之NTP放大攻击
  12. FFmpeg进阶:给视频添加文字水印
  13. firefly-rk3288点mipi屏TV080WUM-NL0有显示无背光
  14. CodingTrip - 携程编程大赛-第二题-携程员工运动会场地问题
  15. Java咖啡馆---品味第一杯咖啡
  16. 不吹不黑,三年赶超阿里云,华为这次是认真的!
  17. 22春天津大学《国际金融学》在线作业二
  18. 玩转 Jasper Report(1) Jaspersoft Studio 安装使用教程
  19. 有源滤波器空间矢量不定频滞环控制matlab仿真
  20. [Spring]什么是IOC-好莱坞原则

热门文章

  1. 阿里云 SSL证书部署(DigiCert 免费版 SSL)
  2. echarts dataZoom组件
  3. 【自用】华南师范大学918c++程序设计选填错题
  4. clojure/core every?
  5. java jpanel 半透明_java – 透明JPanel
  6. usermod命令、用户密码管理以及mkpasswd命令
  7. java ssl连接(no cipher suites in common)
  8. 克莱尼星号-Kleene星号
  9. 织梦配置html,织梦网站后台的基本设置
  10. master - master (non-fast-forward)和git ! [rejected] master - master (fetch first)