金鳞

目标->软件测试架构师

关于oracle 10g中参数optimizer_mode的测试

今天,在资料上看到如下内容:



感到很疑惑:真的是这样么,10g中的rule和choose是无效的选项?

但我测试时,也能设置choose啊,而且执行计划和all_Rows确实不一样啊!

问了一下网上的朋友,又作了些测试如下,结果也在下面:


C:\Documents and Settings\Administrator>sqlplus system/manager

SQL*Plus: Release 10.2.0.1.0 - Production on 星期五 3月 19 14:06:01 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> show parameter optimizer_mode

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_mode string ALL_ROWS

SQL> alter session set optimizer_mode=rule;

会话已更改。

SQL> show parameter optimizer_mode

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_mode string RULE

SQL> set autotrace on

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


执行计划
----------------------------------------------------------
Plan hash value: 1078166315

--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | FIXED TABLE FULL| X$VERSION |
--------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("INST_ID"=USERENV('INSTANCE'))

Note
-----
   - rule based optimizer used (consider using cbo) --Oracle给出的提示


统计信息
----------------------------------------------------------
          8 recursive calls
          0 db block gets
          2 consistent gets
          0 physical reads
          0 redo size
        680 bytes sent via SQL*Net to client
        385 bytes received via SQL*Net from client
          2 SQL*Net roundtrips to/from client
          0 sorts (memory)
          0 sorts (disk)
          5 rows processed

SQL> alter session set optimizer_mode=chooose;

ERROR:
ORA-00096: 值 CHOOOSE 对参数 optimizer_mode 无效, 它必须来自 first_rows_1000,
first_rows_100, first_rows_10, first_rows_1, first_rows, all_rows, choose, rule
之间

-->一次错误输入,得到了参数的选项值

SQL> alter session set optimizer_mode=choose;

会话已更改。

SQL> show parameter optimizer_mode

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_mode string CHOOSE
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


执行计划
----------------------------------------------------------
Plan hash value: 1078166315

--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
|* 1 | FIXED TABLE FULL| X$VERSION |
--------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("INST_ID"=USERENV('INSTANCE'))

Note
-----
   - rule based optimizer used (consider using cbo) --Oracle给出的提示


统计信息
----------------------------------------------------------
          8 recursive calls
          0 db block gets
          2 consistent gets
          0 physical reads
          0 redo size
        680 bytes sent via SQL*Net to client
        385 bytes received via SQL*Net from client
          2 SQL*Net roundtrips to/from client
          0 sorts (memory)
          0 sorts (disk)
          5 rows processed

SQL> alter session set optimizer_mode=all_rows;

会话已更改。

SQL> show parameter optimizer_mode

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_mode string ALL_ROWS

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production


执行计划
----------------------------------------------------------
Plan hash value: 1078166315

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 47 | 0 (0)| 00:00:01 |
|* 1 | FIXED TABLE FULL| X$VERSION | 1 | 47 | 0 (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("INST_ID"=USERENV('INSTANCE'))


统计信息
----------------------------------------------------------
          8 recursive calls
          0 db block gets
          2 consistent gets
          0 physical reads
          0 redo size
        680 bytes sent via SQL*Net to client
        385 bytes received via SQL*Net from client
          2 SQL*Net roundtrips to/from client
          0 sorts (memory)
          0 sorts (disk)
          5 rows processed

SQL>


测试结果:
  1,并非如资料中所言,rule,choose仍然是有效选项,可以选择。
  2,但rule和choose非oracle推荐值,当设置为rule或choose时,oracle会在执行计划中给出提示:- rule based optimizer used (consider using cbo)
  3,oracle10g中optimizer_mode选择范围: first_rows_1000,first_rows_100,first_rows_10, first_rows_1, first_rows, all_rows, choose, rule。
  4,此测试必须在oracle10g的sqlplus中执行,我开始在8i中不会有那条提示。
  5,书中也会有错误,不可尽信~~

转帖请注明:
本文源自TTT BLOG,原文地址:http://blog.chinaunix.net/u3/107265/showart_2201600.html
posted on 2010-04-28 17:00 金鳞 阅读(892) 评论(0)  编辑 收藏 引用 所属分类: Oracle
只有注册用户登录后才能发表评论。