抓取全表掃描的表,篩選和分析
select a.hash_value, b.object_owner, b.object_name, a.EXECUTIONS
from v$sql a, v$sql_plan b
where a.hash_value = b.HASH_VALUE
and a.PLAN_HASH_VALUE = b.plan_hash_value
and a.CHILD_NUMBER = b.CHILD_NUMBER
and b.object_type = 'TABLE'
and b.options like 'FULL%'
and b.object_owner not in ('SYS', 'SYSTEM', 'DBMGR')
group by a.hash_value, b.OBJECT_OWNER, b.object_name, a.executions;
SELECT a.snap_id,
TO_CHAR(begin_INTERVAL_TIME, 'yyyy-mm-dd hh24:mi:ss'),
a.stat_name,
a.VALUE
FROM dba_hist_sysstat a, dba_hist_snapshot b
WHERE a.snap_id = b.snap_id
and a.stat_name = 'table scan rows gotten'
and a.snap_id >= '52251'
order by snap_id desc;
------
from ft_scan_0907_1230_rows
Results_sql;
from ft_scan_0910_0200PM a, ft_scan_0910_0215PM b, ft_scan_0910_rows c
where a.hash_value = b.hash_value
and a.table_name = b.table_name
and a.table_name = c.table_name
group by a.owner,a.table_name,c.counts
order by a.table_name;
______________________
(
timstamp date,
hash_value number (15,0),
plan_hash_value number (15,0),
child_number number (15,0),
owner VARCHAR2(30),
table_name VARCHAR2(30),
executions NUMBER (15,0)
)
TABLESPACE USERS
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
Results_10Sep_14;00-14;30_2snapshot.xls - -
-----------------------------------------------
select t1.owner,
t1.table_name,
(t1.exec_by_counts + t2.exec_by_counts)
from (select a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts,
(b.sum_executions - a.sum_executions) * c.counts exec_by_counts
from ft_scan_0910_0200PM_sum a,
ft_scan_0910_0215PM_sum b,
ft_scan_0910_rows c
where a.table_name = b.table_name
and a.table_name = c.table_name
group by a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts) t1,
(select a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts,
(b.sum_executions - a.sum_executions) * c.counts exec_by_counts
from ft_scan_0910_0215PM_sum a,
ft_scan_0910_0230PM_sum b,
ft_scan_0910_rows c
where a.table_name = b.table_name
and a.table_name = c.table_name
group by a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts) t2
and t1.table_name = t2.table_name
group by t1.owner, t1.table_name,(t1.exec_by_counts + t2.exec_by_counts)
order by (t1.exec_by_counts + t2.exec_by_counts)desc;
================================================================================
建立2箇中間過程view,
as
select a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts,
(b.sum_executions - a.sum_executions) * c.counts exec_by_counts
from ft_scan_0910_0200PM_sum a,
ft_scan_0910_0215PM_sum b,
ft_scan_0910_rows c
where a.table_name = b.table_name
and a.table_name = c.table_name
and (b.sum_executions - a.sum_executions) >=0
group by a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts ;
-----------------------------------------------------------------------------------
as
select a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts,
(b.sum_executions - a.sum_executions) * c.counts exec_by_counts
from ft_scan_0910_0215PM_sum a,
ft_scan_0910_0230PM_sum b,
ft_scan_0910_rows c
where a.table_name = b.table_name
and a.table_name = c.table_name
and (b.sum_executions - a.sum_executions) >=0
group by a.owner,
a.table_name,
(b.sum_executions - a.sum_executions),
c.counts ;
兩個snapshot時間段內的所有table 的 delta_sum_executions.
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name = t2.table_name(+)
group by t1.owner, t1.table_name
union
select t2.owner, t2.table_name, sum(nvl(t1.delta_sum_executions,0)+nvl(t2.delta_sum_executions,0)) delta_sum_executions
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name(+) = t2.table_name
group by t2.owner, t2.table_name
select t.owner,
t.table_name,
t.delta_sum_executions,
c.counts,
t.delta_sum_executions * c.counts
from (select t1.owner,
t1.table_name,
sum(nvl(t1.delta_sum_executions, 0) +
nvl(t2.delta_sum_executions, 0)) delta_sum_executions
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name = t2.table_name(+)
group by t1.owner, t1.table_name
union
select t2.owner,
t2.table_name,
sum(nvl(t1.delta_sum_executions, 0) +
nvl(t2.delta_sum_executions, 0)) delta_sum_executions
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name(+) = t2.table_name
group by t2.owner, t2.table_name) T,
ft_scan_0910_rows c
where t.table_name = c.table_name
group by t.owner,t.table_name,t.delta_sum_executions,c.counts
order by t.delta_sum_executions * c.counts desc;
from DBMGR.ft_size_analzyed M,
ft_scan_blocks_sum S,
(select t.owner,
t.table_name,
t.delta_sum_executions,
c.counts,
t.delta_sum_executions * c.counts
from (select t1.owner,
t1.table_name,
sum(nvl(t1.delta_sum_executions, 0) +
nvl(t2.delta_sum_executions, 0)) delta_sum_executions
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name = t2.table_name(+)
group by t1.owner, t1.table_name
union
select t2.owner,
t2.table_name,
sum(nvl(t1.delta_sum_executions, 0) +
nvl(t2.delta_sum_executions, 0)) delta_sum_executions
from ft_view_t1 t1, ft_view_t2 t2
where t1.table_name(+) = t2.table_name
group by t2.owner, t2.table_name) T,
ft_scan_0910_rows c
where t.table_name = c.table_name
group by t.owner, t.table_name, t.delta_sum_executions, c.counts) N
and m.table_name = s.table_name(+)
order by m.owner,m.table_name,m.counts,m.num_rows,m.last_analyzed,n.delta_sum_executions,n.counts,n.delta_sum_executions * n.counts,m.size_m
例項001----- 透過Oracle的包dbms_space.space_usage 計算表ft_scan_tables 中所列出的tables的blocks. 然後將結果輸出至 ft_scan_blocks.
select * from ft_scan_tables;
OWNER |
TABLE_NAME |
TYPE |
FGLPA |
QUEST_ADV_MON_VERSION |
TABLE |
FGLPA |
QUEST_ADV_SNAPSHOT_CTRL |
TABLE |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
declare
v_unformatted_blocks number;
v_unformatted_bytes number;
v_fs1_blocks number;
v_fs1_bytes number;
v_fs2_blocks number;
v_fs2_bytes number;
v_fs3_blocks number;
v_fs3_bytes number;
v_fs4_blocks number;
v_fs4_bytes number;
v_full_blocks number;
v_full_bytes number;
begin
for i in( select owner,table_name,type from dbmgr.ft_scan_tables where owner not in ('OUTLN','FOGLIGHT','LBACSYS')) loop
dbms_space.space_usage (i.owner,i.table_name,i.type, v_unformatted_blocks,
v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes,
v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes);
dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
dbms_output.put_line('Full Blocks = '||v_full_blocks);
insert into dbmgr.ft_scan_blocks(owner,table_name,type,Unformatted, FS1 ,FS2 ,FS3 ,FS4 ,Full)
select i.owner,i.table_name,i.type, v_unformatted_blocks ,v_fs1_blocks , v_fs2_blocks ,v_fs3_blocks ,v_fs4_blocks , v_full_blocks from dual;
end loop;
commit;
end;
/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
--- 上述迴圈結果輸出至表 ft_scan_blocks.
select * from dbmgr.ft_scan_blocks
OWNER |
TABLE_NAME |
TYPE |
UNFORMATTED |
FS1 |
FS2 |
FS3 |
FS4 |
FULL |
LIFEDATA |
L_PM_RANK_INFO |
TABLE |
0 |
0 |
4 |
4 |
38 |
14 |
LIFEBASE |
LCS_QUALITY_TYPE_TBL |
TABLE |
28 |
0 |
0 |
0 |
32 |
0 |
LIFEDATA |
LDC_CLIENT_SPLIT_REPORT |
TABLE |
0 |
0 |
0 |
0 |
5 |
0 |
select * from dbmgr.ft_scan_blocks;
truncate table dbmgr.ft_scan_blocks;
Partition tables 要採取下面的方法計算blocks.
++++++++++++++++++++++++++++++++++++++++++
-- Create table
create table TEST1
(
owner VARCHAR2(200),
table_name VARCHAR2(500),
type VARCHAR2(100),
partition_name varchar2(100),
unformatted NUMBER,
fs1 NUMBER,
fs2 NUMBER,
fs3 NUMBER,
fs4 NUMBER,
full NUMBER
);
create table ft_scan_blocks1(owner,table_name,type,partition_name) as
select table_owner,table_name,'TABLE PARTITION',partition_name
from dba_tab_partitions where (table_owner = 'LIFEDATA' and table_name in ('LCS_BONUS_DETAIL')) or (table_owner = 'LIFEDATAARC' and table_name = 'MONTHLY_SALARY_PROVIDE_H')
union all
select table_owner,table_name,'TABLE SUBPARTITION',subpartition_name
from dba_tab_subpartitions where (table_owner = 'LIFEDATA' and table_name in ('E_LETTER_REPOSITORY'))
declare
v_unformatted_blocks number;
v_unformatted_bytes number;
v_fs1_blocks number;
v_fs1_bytes number;
v_fs2_blocks number;
v_fs2_bytes number;
v_fs3_blocks number;
v_fs3_bytes number;
v_fs4_blocks number;
v_fs4_bytes number;
v_full_blocks number;
v_full_bytes number;
begin
for i in( select owner,table_name,type,partition_name from dbmgr.ft_scan_blocks1 ) loop
dbms_space.space_usage (i.owner,i.table_name,i.type, v_unformatted_blocks,
v_unformatted_bytes, v_fs1_blocks, v_fs1_bytes, v_fs2_blocks, v_fs2_bytes,
v_fs3_blocks, v_fs3_bytes, v_fs4_blocks, v_fs4_bytes, v_full_blocks, v_full_bytes,i.partition_name);
dbms_output.put_line('Unformatted Blocks = '||v_unformatted_blocks);
dbms_output.put_line('FS1 Blocks = '||v_fs1_blocks);
dbms_output.put_line('FS2 Blocks = '||v_fs2_blocks);
dbms_output.put_line('FS3 Blocks = '||v_fs3_blocks);
dbms_output.put_line('FS4 Blocks = '||v_fs4_blocks);
dbms_output.put_line('Full Blocks = '||v_full_blocks);
insert into dbmgr.test1(owner,table_name,type,partition_name,Unformatted, FS1 ,FS2 ,FS3 ,FS4 ,Full)
select i.owner,i.table_name,i.type,i.partition_name, v_unformatted_blocks ,v_fs1_blocks , v_fs2_blocks ,v_fs3_blocks ,v_fs4_blocks , v_full_blocks from dual;
commit;
end loop;
end;
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22578826/viewspace-745252/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL中的全表掃描和索引樹掃描MySql索引
- 優化全表掃描優化
- delete 與全表掃描delete
- 一條全表掃描sql語句的分析SQL
- 查詢全表掃描的sqlSQL
- ORACLE全表掃描查詢Oracle
- 有索引卻走全表掃描的實驗分析索引
- oracle 全表掃描,索引範圍掃描與塊的理解Oracle索引
- 使用索引快速全掃描(Index FFS)避免全表掃描的若干場景索引Index
- 查詢全表掃描語句
- oracle優化:避免全表掃描Oracle優化
- oracle是如何進行全表掃描的Oracle
- 優化Oracle with全表掃描的問題優化Oracle
- Oracle中存取資料掃描Table及索引的方式(全表掃描,索引掃描等)Oracle索引
- (轉)索引掃描還是全表掃描(Index Scan Or Full Table Scan)索引Index
- 轉)索引掃描還是全表掃描(Index Scan Or Full Table Scan)索引Index
- 使用全表掃描快取大表的相關問題快取
- 優化Oracle with全表掃描的問題(二)優化Oracle
- 索引全掃描和索引快速全掃描的區別索引
- delete 刪除資料 全表掃描還是掃描所有塊的測試delete
- 24_Oracle資料庫全表掃描詳解(四)_全表掃描生產最佳化案例三則Oracle資料庫
- noworkload下全表掃描cost的計算
- oracle實驗記錄(分割槽全表掃描(全區掃描) FTS 時候的成本計算)Oracle
- 隱形轉換導致全表掃描案例
- 關於分割槽表中的全partition掃描問題
- oracle sql tuning 8--優化全表掃描OracleSQL優化
- Greenplum儲存過程使用分割槽表將進行全表掃描儲存過程
- 全表掃描的cost 與 索引掃描Cost的比較 – 無直方圖(10.1.0.3以後)索引直方圖
- PostgreSQL DBA(55) - MVCC#8(對全表掃描的影響)SQLMVCC#
- 23_Oracle資料庫全表掃描詳解(三)Oracle資料庫
- 22_Oracle資料庫全表掃描詳解(二)Oracle資料庫
- 21_Oracle資料庫全表掃描詳解(一)Oracle資料庫
- 關係型資料庫全表掃描分片詳解資料庫
- 使用10046 event trace跟蹤全表掃描操作
- oracle實驗記錄 (全表掃描COST計算方法)Oracle
- 怎麼解決因全表掃描帶來的 Buffer Pool 汙染
- 查詢出資料庫中預設會以全表掃描方式訪問的表資料庫
- MongoDB Primary 為何持續出現 oplog 全表掃描?MongoDB