[20150706]11G cardinality feedback问题

[20150706]11G cardinality feedback问题.txt

--今天做一个测试例子,第1次遇到cardinality feedback的问题

1.建立测试环境:

SCOTT@test> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

create table t1 as select rownum id1, trunc(rownum/10)+1 id2,cast('t1test' as varchar2(20)) pad1 from xmltable('1 to 100000');
create table t2 as select lpad(rownum,10,'0') id1, cast('t2test' as varchar2(20)) pad2 from xmltable('1 to 100000');
create table t3 as select rownum id1, trunc(dbms_random.value(0,100)) x1,trunc(dbms_random.value(0,200)) x2,cast('t3test' as varchar2(20)) pad3 from xmltable('1 to 100000');
create table t4 as select * from t3 where 1=2;
--t4是空表,主要目的这样与生产系统信息符合.没有什么其它意思.
--另外T2表字段id1是字符型的,问题主要在这里。

create unique index pk_t1 on t1 (ID1);
alter table t1 add constraint pk_t1 primary key (id1);
create index i_t1_id2 on t1 (ID2);

create index pk_t2 on t2 (to_number(ID1));
create index i_t3_id1 on t3 (ID1);
create index i_t4_id1 on t4 (ID1);

--分析表忽略.Method_Opt => 'FOR ALL COLUMNS SIZE 1 '

create view v_t3t4  as select * from t3 union all select * from t4;

create or replace view v_tall as
select t1.id1,t1.id2,t1.pad1,t2.pad2,sum_x1,sum_x2
from t1,t2,
(select id1,sum(x1) sum_x1,sum(x2) sum_x2 from v_t3t4 group by id1) vx
where t1.id1=to_number(t2.id1) and t1.id1=vx.id1;

2.开始测试:

select * from v_tall where id2=42;

--执行计划如下:
SCOTT@test> @dpc '' outline
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  09qkq6x7ju4x2, child number 0
-------------------------------------
select * from v_tall where id2=42

Plan hash value: 431511531

------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name     | E-Rows |E-Bytes| Cost (%CPU)| E-Time   |  OMem |  1Mem | Used-Mem |
------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |          |        |       |    53 (100)|          |       |       |          |
|   1 |  HASH GROUP BY                  |          |     10 |   700 |    53   (2)| 00:00:01 |   766K|   766K| 1220K (0)|
|   2 |   NESTED LOOPS                  |          |     10 |   700 |    52   (0)| 00:00:01 |       |       |          |
|   3 |    NESTED LOOPS                 |          |     10 |   390 |    22   (0)| 00:00:01 |       |       |          |
|   4 |     TABLE ACCESS BY INDEX ROWID | T1       |     10 |   160 |     2   (0)| 00:00:01 |       |       |          |
|*  5 |      INDEX RANGE SCAN           | I_T1_ID2 |     10 |       |     1   (0)| 00:00:01 |       |       |          |
|   6 |     TABLE ACCESS BY INDEX ROWID | T2       |      1 |    23 |     2   (0)| 00:00:01 |       |       |          |
|*  7 |      INDEX RANGE SCAN           | PK_T2    |      1 |       |     1   (0)| 00:00:01 |       |       |          |
|   8 |    VIEW                         | V_T3T4   |      1 |    31 |     3   (0)| 00:00:01 |       |       |          |
|   9 |     UNION ALL PUSHED PREDICATE  |          |        |       |            |          |       |       |          |
|  10 |      TABLE ACCESS BY INDEX ROWID| T3       |      1 |    12 |     2   (0)| 00:00:01 |       |       |          |
|* 11 |       INDEX RANGE SCAN          | I_T3_ID1 |      1 |       |     1   (0)| 00:00:01 |       |       |          |
|  12 |      TABLE ACCESS BY INDEX ROWID| T4       |      1 |    39 |     1   (0)| 00:00:01 |       |       |          |
|* 13 |       INDEX RANGE SCAN          | I_T4_ID1 |      1 |       |     1   (0)| 00:00:01 |       |       |          |
------------------------------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

   1 - SEL$25E2CB83
   4 - SEL$25E2CB83 / T1@SEL$2
   5 - SEL$25E2CB83 / T1@SEL$2
   6 - SEL$25E2CB83 / T2@SEL$2
   7 - SEL$25E2CB83 / T2@SEL$2
   8 - SET$5715CE2E / V_T3T4@SEL$3
   9 - SET$5715CE2E
  10 - SEL$8E13D68A / T3@SEL$4
  11 - SEL$8E13D68A / T3@SEL$4
  12 - SEL$9384AC1D / T4@SEL$5
  13 - SEL$9384AC1D / T4@SEL$5

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('11.2.0.3')
      DB_VERSION('11.2.0.3')
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$8E13D68A")
      OUTLINE_LEAF(@"SEL$9384AC1D")
      OUTLINE_LEAF(@"SET$5715CE2E")
      PUSH_PRED(@"SEL$25E2CB83" "V_T3T4"@"SEL$3" 3)
      OUTLINE_LEAF(@"SEL$25E2CB83")
      MERGE(@"SEL$3")
      OUTLINE(@"SEL$4")
      OUTLINE(@"SEL$5")
      OUTLINE(@"SET$1")
      OUTLINE(@"SEL$25E2CB83")
      MERGE(@"SEL$3")
      OUTLINE(@"SEL$F5BB74E1")
      MERGE(@"SEL$2")
      OUTLINE(@"SEL$3")
      OUTLINE(@"SEL$1")
      OUTLINE(@"SEL$2")
      INDEX_RS_ASC(@"SEL$25E2CB83" "T1"@"SEL$2" ("T1"."ID2"))
      INDEX_RS_ASC(@"SEL$25E2CB83" "T2"@"SEL$2" "PK_T2")
      NO_ACCESS(@"SEL$25E2CB83" "V_T3T4"@"SEL$3")
      LEADING(@"SEL$25E2CB83" "T1"@"SEL$2" "T2"@"SEL$2" "V_T3T4"@"SEL$3")
      USE_NL(@"SEL$25E2CB83" "T2"@"SEL$2")
      USE_NL(@"SEL$25E2CB83" "V_T3T4"@"SEL$3")
      USE_HASH_AGGREGATION(@"SEL$25E2CB83")
      INDEX_RS_ASC(@"SEL$9384AC1D" "T4"@"SEL$5" ("T4"."ID1"))
      INDEX_RS_ASC(@"SEL$8E13D68A" "T3"@"SEL$4" ("T3"."ID1"))
      END_OUTLINE_DATA
  */

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

   5 - access("T1"."ID2"=42)
   7 - access("T1"."ID1"="T2"."SYS_NC00003$")
  11 - access("ID1"="T1"."ID1")
  13 - access("ID1"="T1"."ID1")
--存在一个谓词推入,很好的选择执行计划:
--PUSH_PRED(@"SEL$25E2CB83" "V_T3T4"@"SEL$3" 3)

3.而第2次执行:
SCOTT@test> @dpc '' outline
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  09qkq6x7ju4x2, child number 1
-------------------------------------
select * from v_tall where id2=42
Plan hash value: 3589297038
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                     | Name     | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers | Reads  | Writes |  OMem |  1Mem | Used-Mem | Used-Tmp|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |          |      1 |        |       |   119 (100)|          |     10 |00:00:01.62 |     339 |    300 |    300 |       |       |          |         |
|*  1 |  HASH JOIN                    |          |      1 |     11 |   737 |   119   (2)| 00:00:01 |     10 |00:00:01.62 |     339 |    300 |    300 |   981K|   981K|  890K (0)|         |
|   2 |   NESTED LOOPS                |          |      1 |     10 |   280 |    22   (0)| 00:00:01 |     10 |00:00:00.01 |      12 |      0 |      0 |       |       |          |         |
|   3 |    TABLE ACCESS BY INDEX ROWID| T1       |      1 |     10 |   160 |     2   (0)| 00:00:01 |     10 |00:00:00.01 |       3 |      0 |      0 |       |       |          |         |
|*  4 |     INDEX RANGE SCAN          | I_T1_ID2 |      1 |     10 |       |     1   (0)| 00:00:01 |     10 |00:00:00.01 |       2 |      0 |      0 |       |       |          |         |
|   5 |    TABLE ACCESS BY INDEX ROWID| T2       |     10 |      1 |    12 |     2   (0)| 00:00:01 |     10 |00:00:00.01 |       9 |      0 |      0 |       |       |          |         |
|*  6 |     INDEX RANGE SCAN          | PK_T2    |     10 |      1 |       |     1   (0)| 00:00:01 |     10 |00:00:00.01 |       8 |      0 |      0 |       |       |          |         |
|   7 |   VIEW                        |          |      1 |     11 |   429 |    97   (3)| 00:00:01 |    100K|00:00:01.33 |     327 |    300 |    300 |       |       |          |         |
|   8 |    HASH GROUP BY              |          |      1 |     11 |   341 |    97   (3)| 00:00:01 |    100K|00:00:01.13 |     327 |    300 |    300 |  6485K|  2233K| 3353K (1)|    3072 |
|   9 |     VIEW                      | V_T3T4   |      1 |     11 |   341 |    96   (2)| 00:00:01 |    100K|00:00:00.70 |     327 |      0 |      0 |       |       |          |         |
|  10 |      UNION-ALL                |          |      1 |        |       |            |          |    100K|00:00:00.50 |     327 |      0 |      0 |       |       |          |         |
|  11 |       TABLE ACCESS FULL       | T3       |      1 |     10 |   120 |    94   (2)| 00:00:01 |    100K|00:00:00.10 |     327 |      0 |      0 |       |       |          |         |
|  12 |       TABLE ACCESS FULL       | T4       |      1 |      1 |    39 |     2   (0)| 00:00:01 |      0 |00:00:00.01 |       0 |      0 |      0 |       |       |          |         |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------

   1 - SEL$F5BB74E1
   3 - SEL$F5BB74E1 / T1@SEL$2
   4 - SEL$F5BB74E1 / T1@SEL$2
   5 - SEL$F5BB74E1 / T2@SEL$2
   6 - SEL$F5BB74E1 / T2@SEL$2
   7 - SEL$3        / VX@SEL$2
   8 - SEL$3
   9 - SET$1        / V_T3T4@SEL$3
  10 - SET$1
  11 - SEL$4        / T3@SEL$4
  12 - SEL$5        / T4@SEL$5

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('11.2.0.3')
      DB_VERSION('11.2.0.3')
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$4")
      OUTLINE_LEAF(@"SEL$5")
      OUTLINE_LEAF(@"SET$1")
      OUTLINE_LEAF(@"SEL$3")
      OUTLINE_LEAF(@"SEL$F5BB74E1")
      MERGE(@"SEL$2")
      OUTLINE(@"SEL$1")
      OUTLINE(@"SEL$2")
      INDEX_RS_ASC(@"SEL$F5BB74E1" "T1"@"SEL$2" ("T1"."ID2"))
      INDEX_RS_ASC(@"SEL$F5BB74E1" "T2"@"SEL$2" "PK_T2")
      NO_ACCESS(@"SEL$F5BB74E1" "VX"@"SEL$2")
      LEADING(@"SEL$F5BB74E1" "T1"@"SEL$2" "T2"@"SEL$2" "VX"@"SEL$2")
      USE_NL(@"SEL$F5BB74E1" "T2"@"SEL$2")
      USE_HASH(@"SEL$F5BB74E1" "VX"@"SEL$2")
      NO_ACCESS(@"SEL$3" "V_T3T4"@"SEL$3")
      USE_HASH_AGGREGATION(@"SEL$3")
      FULL(@"SEL$5" "T4"@"SEL$5")
      FULL(@"SEL$4" "T3"@"SEL$4")
      END_OUTLINE_DATA
  */

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

   1 - access("T1"."ID1"="VX"."ID1")
   4 - access("T1"."ID2"=42)
   6 - access("T1"."ID1"="T2"."SYS_NC00003$")

Note
-----
   - cardinality feedback used for this statement

--不过这个问题我在一台11.2.0.4的机器测试,无法重现。估计是bug。

时间: 2024-11-15 12:08:02

[20150706]11G cardinality feedback问题的相关文章

[20150428]11G SPM与cardinality feedback

[20150428]11G SPM与cardinality feedback问题.txt 1.问题说明: SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- --------------------------------------------------------------------------------

[20150706]11G谓词推入问题.txt

[20150706]11G谓词推入问题.txt --生产系统遇到一个sql语句的问题. --生产系统的sql语句比较复杂,做一个简化的例子来说明问题.来说明自己优化遇到的困惑. 1.建立测试环境: SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- ----------------------------------

oracle中Cardinality Feedback与_optimizer_use_feedback的使用建议

该参数与Cardinality Feedback特性有关,优化器可以估算基数不正确的原因有很多,如缺少的统计信息,不准确的统计数据,或复杂的谓词,基数统计反馈有助于优化器生成更合理的执行计划.对于此特性我不作科普了,比较详细的资料可以参考以下文档: 1.Tuning-by-Cardinality-Feedback.pdf 2.Statistics (Cardinality) Feedback – Frequently Asked Questions (文档 ID 1344937.1) 该特性其实

[20130305]Cardinality Feedback on 11gR2.txt

[20130305]Cardinality Feedback on 11gR2.txt http://blogs.oracle.com/optimizer/entry/cardinality_feedback Cardinality Feedback是11G的新特性,它可以自动调整执行计划.但是具体如何实现的呢?按照上面的链接的例子做一些测试看看. 1.测试环境以及问题提出: SQL> select * from v$version where rownum BANNER -----------

那些语句使用cardinality feedback

[20140122]那些语句使用cardinality feedback.txt cardinality feedback是11G的新特性,昨天别人问一个问题,在11G下如何知道那些sql语句使用了cardinality feedback. 实际上这些信息保存在v$sql_plan或者DBA_HIST_SQL_PLAN的other_xml里面,里面的信息是XML格式的,对这些语句如何写我自. 己从来记不住. 简单一点: select * from v$sql_plan where other_x

基数反馈(Cardinality Feedback)

基数反馈(Cardinality Feedback) Cardinality Feedback Cardinality Feedback基数反馈是版本11.2(11.2.0.1及以后)中引入的关于SQL 性能优化的新特性,该特性主要针对 统计信息陈旧.无直方图或虽然有直方图但仍基数计算不准确的情况,Cardinality基数的计算直接影响到后续的JOIN COST等重要的成本计算评估,造成CBO选择不当的执行计划.以上是Cardinality Feedback特性引入的初衷. 发生情景: 在普通

[20150430]11G SPM与cardinality feedback2

[20150430]11G SPM与cardinality feedback问题2.txt 1.问题说明: SCOTT@test> @ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- -------------------------------------------------------------------------------

[20150710]11G谓词推入问题2.txt

[20150710]11G谓词推入问题2.txt --生产系统遇到一个sql语句的问题. --生产系统的sql语句比较复杂,做一个简化的例子来说明问题.来说明自己优化遇到的困惑. --昨天看来别人的回复,加提示 /*+ push_pred(v_tallx)*/,无效.实际上如果仔细看我的帖子 --http://blog.itpub.net/267265/viewspace-1724554/, 可以发现T2表的id是字符类型,存在隐式转换,虽然我定义了函数索引,视乎 --对于这种情况谓词推入存在问

[20141014]11G长时间分析问题.txt

[20141014]11G长时间分析问题.txt http://www.itpub.net/thread-1495845-1-1.html http://space.itpub.net/267265/viewspace-723066 http://blog.itpub.net/267265/viewspace-752117/ --我以前看到这条sql语句,我做了一些简单修改. 1. 问题提出: SCOTT@test> @ver1 PORT_STRING                    VE