+ -
当前位置:首页 → 问答吧 → 执行计划

执行计划

时间:2011-09-14

来源:互联网

create table m_objects as select * from dba_objects;

create index ob_status on m_objects (status);

update m_objects u set u.status='INVALID' WHERE ROWNUM<2

select status,count(*),count(*)*100/(select count(*) from m_objects) from m_objects group by status

           STATUS        COUNT(*)        COUNT(*)*100/(SELECTCOUNT(*)FR
1        INVALID        20                0.0401630620318493
2        VALID                49777        99.9598369379682


analyze index ob_status compute statistics
analyze table  m_objects compute statistics

Issue:

select object_name, owner from mao.m_objects o where status='INVALID'

Plan hash value: 1579104485

-------------------------------------------------------------------------------
| Id  | Operation         | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |           | 24899 |   851K|   159   (3)| 00:00:02 |
|*  1 |  TABLE ACCESS FULL| M_OBJECTS | 24899 |   851K|   159   (3)| 00:00:02 |
-------------------------------------------------------------------------------

1 Why it is choosing the way of table full scan?
2 How I can do to make the sql choose the way of index scan without hint?


SQL> show parameter opti

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
filesystemio_options                 string
object_cache_optimal_size            integer     102400
optimizer_dynamic_sampling           integer     2
optimizer_features_enable            string      10.2.0.1
optimizer_index_caching              integer     90
optimizer_index_cost_adj             integer     80
optimizer_mode                       string      ALL_ROWS
optimizer_secure_view_merging        boolean     TRUE
plsql_optimize_level                 integer     2

[ 本帖最后由 luxueqin521 于 2011-9-14 13:55 编辑 ]

作者: luxueqin521   发布时间: 2011-09-14

统计信息不正确.
它估计有2w多行所以认为 full scan更好.
推荐用 dbms_stats.gather_table_stats 再次收集统计信息.

[ 本帖最后由 emaildba 于 2011-9-14 21:47 编辑 ]

作者: emaildba   发布时间: 2011-09-14

yes, Thanks.

作者: luxueqin521   发布时间: 2011-09-14