@@ -14,26 +14,46 @@ SQL> drop table stale_test1 purge;
1414
1515Table dropped.
1616
17+ SQL> drop table stale_test2 purge;
18+
19+ Table dropped.
20+
1721SQL>
1822SQL> create table stale_test1 (col1 number(10));
1923
2024Table created.
2125
26+ SQL> create table stale_test2 (col1 number(10));
27+
28+ Table created.
29+
2230SQL>
2331SQL> create index stale_test1_i on stale_test1(col1);
2432
2533Index created.
2634
35+ SQL> create index stale_test2_i on stale_test2(col1);
36+
37+ Index created.
38+
2739SQL>
2840SQL> exec dbms_stats.set_table_prefs(user,'stale_test1','stale_percent','5')
2941
3042PL/SQL procedure successfully completed.
3143
44+ SQL> exec dbms_stats.set_table_prefs(user,'stale_test2','stale_percent','5')
45+
46+ PL/SQL procedure successfully completed.
47+
3248SQL>
3349SQL> insert into stale_test1 values (1);
3450
35511 row created.
3652
53+ SQL> insert into stale_test2 values (1);
54+
55+ 1 row created.
56+
3757SQL> commit;
3858
3959Commit complete.
@@ -43,19 +63,24 @@ SQL> exec dbms_stats.gather_table_stats(user,'stale_test1')
4363
4464PL/SQL procedure successfully completed.
4565
66+ SQL> exec dbms_stats.gather_table_stats(user,'stale_test2')
67+
68+ PL/SQL procedure successfully completed.
69+
4670SQL>
4771SQL> PROMPT Table stats are not STALE
4872Table stats are not STALE
4973SQL> PROMPT
5074
5175SQL> select table_name, last_analyzed,stale_stats
5276 2 from user_tab_statistics
53- 3 where table_name in ('STALE_TEST1')
77+ 3 where table_name in ('STALE_TEST1','STALE_TEST2' )
5478 4 order by 1,2;
5579
5680TABLE_NAME LAST_ANALYZED STA
5781------------------------- ------------------- ---
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
5984
6085SQL>
6186SQL> pause p...
@@ -70,6 +95,10 @@ SQL> exec dbms_stats.gather_table_stats(user,'stale_test1')
7095
7196PL/SQL procedure successfully completed.
7297
98+ SQL> exec dbms_stats.gather_table_stats(user,'stale_test2')
99+
100+ PL/SQL procedure successfully completed.
101+
73102SQL>
74103SQL> PROMPT But even though the stats were not stale, statistics have been re-gathered
75104But even though the stats were not stale, statistics have been re-gathered
@@ -79,12 +108,51 @@ SQL> PROMPT
79108
80109SQL> select table_name,last_analyzed,stale_stats
81110 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')
83150 4 order by 1,2;
84151
85152TABLE_NAME LAST_ANALYZED STA
86153------------------------- ------------------- ---
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
88156
89157SQL>
90158SQL> pause p...
@@ -94,12 +162,14 @@ SQL>
94162SQL> DECLARE
95163 2 filter_lst DBMS_STATS.OBJECTTAB := DBMS_STATS.OBJECTTAB();
96164 3 BEGIN
97- 4 filter_lst.extend(1 );
165+ 4 filter_lst.extend(2 );
98166 5 filter_lst(1).ownname := user;
99167 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 /
103173
104174PL/SQL procedure successfully completed.
105175
@@ -114,21 +184,21 @@ SQL> PROMPT We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , optio
114184We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , options=>'gather auto')
115185SQL> PROMPT
116186
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
119189SQL> PROMPT and statistics have only been gathered where there are stale stats.
120190and 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 .
123193SQL> select table_name,last_analyzed,stale_stats
124194 2 from user_tab_statistics
125- 3 where table_name in ('STALE_TEST1')
195+ 3 where table_name in ('STALE_TEST1','STALE_TEST2' )
126196 4 order by 1,2;
127197
128198TABLE_NAME LAST_ANALYZED STA
129199------------------------- ------------------- ---
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
131202
132- SQL>
133203SQL>
134204SQL> spool off
0 commit comments