Skip to content

Commit b61dfa2

Browse files
committed
sr
1 parent c317b0b commit b61dfa2

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

optimizer/stale_reason/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Example view to see why partitions are marked stale.
2+
3+
If the stale reason is 'HIST', then this implies there is new column usage information and instructs gather stats to check whether a new histogram is required.
4+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
connect / as sysdba
2+
set linesize 150
3+
set trims on
4+
set pagesize 1000
5+
column table_name format a40
6+
column partition_name format a40
7+
column table_owner format a25
8+
column stale_reason format a20
9+
break on table_name
10+
11+
create or replace view example_stale_reason as
12+
select table_name,
13+
partition_name,
14+
table_owner,
15+
mods,
16+
num_rows,
17+
case
18+
when stale_reason_code is null
19+
then to_char('---')
20+
else XMLTYPE(replace(DBMS_STATS_INTERNAL.GET_STALE_REASON(stale_reason_code), ' ', '')).extract('/stalenessreason/reason/text()').getstringval()
21+
end stale_reason
22+
from (
23+
select table_name,
24+
t.partition_name,
25+
t.table_owner,
26+
(v.inserts + v.deletes + v.updates) mods,
27+
t.num_rows,
28+
CASE
29+
WHEN t.last_analyzed IS NULL THEN NULL
30+
ELSE ( dbms_stats_internal.is_stale(
31+
o.object_id,
32+
NULL,
33+
NULL,
34+
(v.inserts + v.deletes + v.updates),
35+
t.num_rows,
36+
v.flags
37+
) )
38+
END stale_reason_code
39+
from sys.mon_mods_v v,
40+
dba_objects o,
41+
dba_tab_partitions t
42+
where v.obj# = o.object_id
43+
and o.SUBOBJECT_NAME = t.partition_name
44+
and o.object_name = t.table_name
45+
and o.owner = t.table_owner);
46+
47+
select * from example_stale_reason order by 3,1,2;

0 commit comments

Comments
 (0)