@@ -14,26 +14,46 @@ SQL> drop table stale_test1 purge;
14
14
15
15
Table dropped.
16
16
17
+ SQL> drop table stale_test2 purge;
18
+
19
+ Table dropped.
20
+
17
21
SQL>
18
22
SQL> create table stale_test1 (col1 number(10));
19
23
20
24
Table created.
21
25
26
+ SQL> create table stale_test2 (col1 number(10));
27
+
28
+ Table created.
29
+
22
30
SQL>
23
31
SQL> create index stale_test1_i on stale_test1(col1);
24
32
25
33
Index created.
26
34
35
+ SQL> create index stale_test2_i on stale_test2(col1);
36
+
37
+ Index created.
38
+
27
39
SQL>
28
40
SQL> exec dbms_stats.set_table_prefs(user,'stale_test1','stale_percent','5')
29
41
30
42
PL/SQL procedure successfully completed.
31
43
44
+ SQL> exec dbms_stats.set_table_prefs(user,'stale_test2','stale_percent','5')
45
+
46
+ PL/SQL procedure successfully completed.
47
+
32
48
SQL>
33
49
SQL> insert into stale_test1 values (1);
34
50
35
51
1 row created.
36
52
53
+ SQL> insert into stale_test2 values (1);
54
+
55
+ 1 row created.
56
+
37
57
SQL> commit;
38
58
39
59
Commit complete.
@@ -43,19 +63,24 @@ SQL> exec dbms_stats.gather_table_stats(user,'stale_test1')
43
63
44
64
PL/SQL procedure successfully completed.
45
65
66
+ SQL> exec dbms_stats.gather_table_stats(user,'stale_test2')
67
+
68
+ PL/SQL procedure successfully completed.
69
+
46
70
SQL>
47
71
SQL> PROMPT Table stats are not STALE
48
72
Table stats are not STALE
49
73
SQL> PROMPT
50
74
51
75
SQL> select table_name, last_analyzed,stale_stats
52
76
2 from user_tab_statistics
53
- 3 where table_name in ('STALE_TEST1')
77
+ 3 where table_name in ('STALE_TEST1','STALE_TEST2' )
54
78
4 order by 1,2;
55
79
56
80
TABLE_NAME LAST_ANALYZED STA
57
81
------------------------- ------------------- ---
58
- STALE_TEST1 07:22:39 2018-03-16 NO
82
+ STALE_TEST1 09:49:24 2018-03-20 NO
83
+ STALE_TEST2 09:49:25 2018-03-20 NO
59
84
60
85
SQL>
61
86
SQL> pause p...
@@ -70,6 +95,10 @@ SQL> exec dbms_stats.gather_table_stats(user,'stale_test1')
70
95
71
96
PL/SQL procedure successfully completed.
72
97
98
+ SQL> exec dbms_stats.gather_table_stats(user,'stale_test2')
99
+
100
+ PL/SQL procedure successfully completed.
101
+
73
102
SQL>
74
103
SQL> PROMPT But even though the stats were not stale, statistics have been re-gathered
75
104
But even though the stats were not stale, statistics have been re-gathered
@@ -79,12 +108,51 @@ SQL> PROMPT
79
108
80
109
SQL> select table_name,last_analyzed,stale_stats
81
110
2 from user_tab_statistics
82
- 3 where table_name in ('STALE_TEST1')
111
+ 3 where table_name in ('STALE_TEST1','STALE_TEST2')
112
+ 4 order by 1,2;
113
+
114
+ TABLE_NAME LAST_ANALYZED STA
115
+ ------------------------- ------------------- ---
116
+ STALE_TEST1 09:49:29 2018-03-20 NO
117
+ STALE_TEST2 09:49:29 2018-03-20 NO
118
+
119
+ SQL>
120
+ SQL> pause p...
121
+ p...
122
+
123
+ SQL>
124
+ SQL> PROMPT Make STALE_TEST2 stale
125
+ Make STALE_TEST2 stale
126
+ SQL> PROMPT
127
+
128
+ SQL> insert into stale_test2 values (10);
129
+
130
+ 1 row created.
131
+
132
+ SQL> insert into stale_test2 values (10);
133
+
134
+ 1 row created.
135
+
136
+ SQL> commit;
137
+
138
+ Commit complete.
139
+
140
+ SQL>
141
+ SQL> exec dbms_stats.flush_database_monitoring_info
142
+
143
+ PL/SQL procedure successfully completed.
144
+
145
+ SQL>
146
+ SQL>
147
+ SQL> select table_name,last_analyzed,stale_stats
148
+ 2 from user_tab_statistics
149
+ 3 where table_name in ('STALE_TEST1','STALE_TEST2')
83
150
4 order by 1,2;
84
151
85
152
TABLE_NAME LAST_ANALYZED STA
86
153
------------------------- ------------------- ---
87
- STALE_TEST1 07:22:43 2018-03-16 NO
154
+ STALE_TEST1 09:49:29 2018-03-20 NO
155
+ STALE_TEST2 09:49:29 2018-03-20 YES
88
156
89
157
SQL>
90
158
SQL> pause p...
@@ -94,12 +162,14 @@ SQL>
94
162
SQL> DECLARE
95
163
2 filter_lst DBMS_STATS.OBJECTTAB := DBMS_STATS.OBJECTTAB();
96
164
3 BEGIN
97
- 4 filter_lst.extend(1 );
165
+ 4 filter_lst.extend(2 );
98
166
5 filter_lst(1).ownname := user;
99
167
6 filter_lst(1).objname := 'stale_test1';
100
- 7 DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>user,obj_filter_list=>filter_lst,options=>'gather auto');
101
- 8 END;
102
- 9 /
168
+ 7 filter_lst(1).ownname := user;
169
+ 8 filter_lst(1).objname := 'stale_test2';
170
+ 9 DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>user,obj_filter_list=>filter_lst,options=>'gather auto');
171
+ 10 END;
172
+ 11 /
103
173
104
174
PL/SQL procedure successfully completed.
105
175
@@ -114,21 +184,21 @@ SQL> PROMPT We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , optio
114
184
We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , options=>'gather auto')
115
185
SQL> PROMPT
116
186
117
- SQL> PROMPT This time the non-stale table have been skipped
118
- This time the non-stale table have been skipped
187
+ SQL> PROMPT This time the non-stale table has been skipped
188
+ This time the non-stale table has been skipped
119
189
SQL> PROMPT and statistics have only been gathered where there are stale stats.
120
190
and statistics have only been gathered where there are stale stats.
121
- SQL> PROMPT You can see this because LAST_ANALYZED time has not changed .
122
- You can see this because LAST_ANALYZED time has not changed .
191
+ SQL> PROMPT You can see if you consider the LAST_ANALYZED time .
192
+ You can see if you consider the LAST_ANALYZED time .
123
193
SQL> select table_name,last_analyzed,stale_stats
124
194
2 from user_tab_statistics
125
- 3 where table_name in ('STALE_TEST1')
195
+ 3 where table_name in ('STALE_TEST1','STALE_TEST2' )
126
196
4 order by 1,2;
127
197
128
198
TABLE_NAME LAST_ANALYZED STA
129
199
------------------------- ------------------- ---
130
- STALE_TEST1 07:22:43 2018-03-16 NO
200
+ STALE_TEST1 09:49:29 2018-03-20 NO
201
+ STALE_TEST2 09:49:36 2018-03-20 NO
131
202
132
- SQL>
133
203
SQL>
134
204
SQL> spool off
0 commit comments