One case in which CBO will make wrong estimation based on accurate and fresh statistics

The DB version is 11.1.

 

Sometimes we design tables like this

 

OPT_CAL_MASTR_DIM(CAL_MASTR_SKID NUMBER not null primary key,

                                MTH_SKID           number not null

 

                              );

In this table, CAL_MASTR_SKID is a subset of MTH_SKID, which is very similar to employee_id and manager_id design.

 

And in reality, we usually need to issue SQL looks like; 

 

 

select 

*from OPT_CAL_MASTR_DIM WHERE CAL_MASTR_SKID = MTH_SKID

 

 

 

When we look at its execution plan, we will get something interesting.

 

3 ---------------------------------------------------------------------------------------
4 | Id  | Operation         | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
5 ---------------------------------------------------------------------------------------
6 |   0 | SELECT STATEMENT  |                   |     1 |  1066 |   748   (3)| 00:00:03 |
7 |*  1 |  TABLE ACCESS FULL| OPT_CAL_MASTR_DIM |     1 |  1066 |   748   (3)| 00:00:03 |
8 ---------------------------------------------------------------------------------------

 

 

But actually,

select

count(*) from OPT_CAL_MASTR_DIM CAL WHERE CAL_MASTR_SKID = MTH_SKID

 

returns 1795 rows.

 

 

I will check whether this still exists in future release.

 The reason I guess is CAL_MASTR_SKID is primary key and CBO think it must return one row based on the assumption that 'PK = one_value'.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值