close

 

 

實驗表未更新造成的錯誤

*******************

create table t as select 1 id,object_name from dba_objects;   /建立測試表 


update t set id=99 where rownum=1; /更新資料列


select id,count(*) from t group by id;

t-1  

exec dbms_stats.gather_table_stats('SYS','T',cascade=>true);  /分析統計資訊
set autotrace traceonly;


select * from t where id=1;  /實際id=1的筆數有50954筆

                                            執行計畫估算的筆數是50955筆,非常接近實際筆數

t-2  

 

set autotrace off;

update t set id=99 where id=1;       /更改資料表資料,實際id=1的筆數為1筆

update set id=1 where rownum=1;  /更改資料表資料,實際id=99的筆數為50954筆

t-3  

 

set autotrace traceonly;

select * from t where id=1;  /再次執行SQL指令看執行計畫,發現ID=1的資料筆數還是50955筆,沒有更新成1筆,表示因為修改資料表,分析資料過時了,執行計畫錯誤

t-4  

  

exec dbms_stats.gather_table_stats('SYS','T',cascade=>true);  /再次分析統計資訊,執行計畫更新了

t-5  

 

小結:

在實際的資料庫環境中,若CBO執行計畫選擇錯誤,DBA要先考慮到是否有地方失誤,比如說此範例

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 to52016 的頭像
    to52016

    Eason [資料科學//Python學習/資料庫] & [拍片&剪片]

    to52016 發表在 痞客邦 留言(0) 人氣()