-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathanalyse_changed_rows.sql
85 lines (73 loc) · 2.61 KB
/
analyse_changed_rows.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--==============================================================================
-- GPI - Gunther Pippèrr
-- Desc: analyse chained rows in the database
--
-- Must be run with dba privileges
--
--
--==============================================================================
-- http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_4005.htm#SQLRF01105
-- http://blog.tanelpoder.com/2009/11/04/detect-chained-and-migrated-rows-in-oracle/
--==============================================================================
set verify off
set linesize 130 pagesize 1000
define USER_NAME ='GPI'
define TABLE_NAME ='COL_T'
define TABLE_SPACE='USERS'
set serveroutput on
----------------------
-- alternative use the utlchain.sql script in oracle_home/rdbms/admin
declare
v_count pls_integer;
begin
select count(*) into v_count
from DBA_TABLES
where owner=upper('&&USER_NAME.')
and table_name ='CHAINED_ROWS';
if v_count < 1 then
dbms_output.put_line('-- Info : create chained row table');
execute immediate 'create table &&USER_NAME..CHAINED_ROWS (
owner_name varchar2(30),
table_name varchar2(30),
cluster_name varchar2(30),
partition_name varchar2(30),
subpartition_name varchar2(30),
head_rowid rowid,
analyze_timestamp date
) tablespace &&TABLE_SPACE.
';
else
dbms_output.put_line('-- Info : use existing chained row table');
end if;
end;
/
select to_char(sysdate,'dd.mm.yyyy hh24:mi') as start_time from dual
/
declare
cursor c_tab is
select table_name,owner
from dba_tables
where owner=upper('&&USER_NAME.')
and table_name like '&&TABLE_NAME.%';
v_count pls_integer;
v_start number:=dbms_utility.get_time;
begin
for rec in c_tab
loop
dbms_output.put_line('-- Info --------------------------------');
dbms_output.put_line('-- Info : start to analyse the table '||rec.owner||'.'||rec.table_name||' at ::'||to_char(sysdate,'dd.mm.yyyy hh24:mi'));
--execute immediate 'analyse table '||rec.owner||'.'||rec.table_name||' list chained rows into '||rec.owner||'.chained_rows';
dbms_output.put_line('-- Info : finish to analyse the table '||rec.owner||'.'||rec.table_name||' at ::'||to_char(sysdate,'dd.mm.yyyy hh24:mi'));
v_count:=v_count+1;
end loop;
dbms_output.put_line('-- Info --------------------------------');
dbms_output.put_line('-- Info : finish to analyse '||v_count||' tables after '||to_char(dbms_utility.get_time-v_start)||'ms');
end;
/
select to_char(sysdate,'dd.mm.yyyy hh24:mi') as end_time from dual
/
select count(*),c.table_name
from &&USER_NAME..CHAINED_ROWS c
group by c.table_name
/
set verify on