oracle差异收集明细,Oracle收集表的数据与统计信息差异
有時候有這樣的煩惱,由于dmp增量到數據庫中,或是大批量數據操作后沒有收集表的統計信息,導致數據庫性能慢。要手工寫腳本檢查。
drop table gather_tcount;
create table gather_tcount
(
TABLE_NAME ?VARCHAR2(30) not null,
gather_time date,
num_rows ? ?number,
user_table_num_rows number
);
comment on table GATHER_TCOUNT
is '統計表的數據量,差距太大的需要收集統計信息';
alter table GATHER_TCOUNT
add constraint pk_gt_name_t primary key (TABLE_NAME, GATHER_TIME);
create or replace procedure p_gather_tcount
as
--統計實際表中數據量和統計信息表中數據量差異
--如果是重新統計,需要先清空gather_tcount的內容
--如果是斷點續統計,不需要清空gather_tcount的內容
v_count number;
v_temp number;
v_tabname_temp varchar2(30);
begin
for c_rows in(select s.table_name,s.num_rows
from user_tables s ?where s.table_name not like '%BAK%'
and s.table_name not like 'BK%' and
s.table_name not like '%TEMP')--過濾掉備份表
loop
v_tabname_temp := c_rows.table_name;
select count(1) into v_temp from gather_tcount where table_name = c_rows.table_name;
--如果是斷點續統計,則不需要重新count表
if(v_temp =0) then
execute immediate 'select count(1) from '||c_rows.table_name into v_count;
execute immediate 'insert into gather_tcount(TABLE_NAME,gather_time,
num_rows,user_table_num_rows) values(:1,:2,:3,:4)'
using c_rows.table_name,sysdate,v_count,c_rows.num_rows;
commit;
end if;
end loop;
exception when others then
execute immediate 'insert into gather_tcount(TABLE_NAME,gather_time,
num_rows,user_table_num_rows) values(:1,:2,:3,:4)'
using v_tabname_temp,sysdate,sqlcode,sqlcode; --錯誤的先中斷
commit;
end;
call p_gather_tcount(); select * from gather_tcount;
總結
以上是生活随笔為你收集整理的oracle差异收集明细,Oracle收集表的数据与统计信息差异的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 锁表次数一般多大_「健身增肌」有些肌肉喜
- 下一篇: 零起点学算法95——弓型矩阵