|
| 1 | +SQL> set echo on |
| 2 | +SQL> @nopart |
| 3 | +SQL> set trims on pagesize 100 linesize 250 |
| 4 | +SQL> column table_name format a25 |
| 5 | +SQL> column partition_or_global format a25 |
| 6 | +SQL> column index_name format a25 |
| 7 | +SQL> |
| 8 | +SQL> alter session set NLS_DATE_FORMAT = 'HH24:MI:SS YYYY-MM-DD'; |
| 9 | + |
| 10 | +Session altered. |
| 11 | + |
| 12 | +SQL> |
| 13 | +SQL> drop table stale_test1 purge; |
| 14 | + |
| 15 | +Table dropped. |
| 16 | + |
| 17 | +SQL> |
| 18 | +SQL> create table stale_test1 (col1 number(10)); |
| 19 | + |
| 20 | +Table created. |
| 21 | + |
| 22 | +SQL> |
| 23 | +SQL> create index stale_test1_i on stale_test1(col1); |
| 24 | + |
| 25 | +Index created. |
| 26 | + |
| 27 | +SQL> |
| 28 | +SQL> exec dbms_stats.set_table_prefs(user,'stale_test1','stale_percent','5') |
| 29 | + |
| 30 | +PL/SQL procedure successfully completed. |
| 31 | + |
| 32 | +SQL> |
| 33 | +SQL> insert into stale_test1 values (1); |
| 34 | + |
| 35 | +1 row created. |
| 36 | + |
| 37 | +SQL> commit; |
| 38 | + |
| 39 | +Commit complete. |
| 40 | + |
| 41 | +SQL> |
| 42 | +SQL> exec dbms_stats.gather_table_stats(user,'stale_test1') |
| 43 | + |
| 44 | +PL/SQL procedure successfully completed. |
| 45 | + |
| 46 | +SQL> |
| 47 | +SQL> PROMPT Table stats are not STALE |
| 48 | +Table stats are not STALE |
| 49 | +SQL> PROMPT |
| 50 | + |
| 51 | +SQL> select table_name, last_analyzed,stale_stats |
| 52 | + 2 from user_tab_statistics |
| 53 | + 3 where table_name in ('STALE_TEST1') |
| 54 | + 4 order by 1,2; |
| 55 | + |
| 56 | +TABLE_NAME LAST_ANALYZED STA |
| 57 | +------------------------- ------------------- --- |
| 58 | +STALE_TEST1 07:22:39 2018-03-16 NO |
| 59 | + |
| 60 | +SQL> |
| 61 | +SQL> pause p... |
| 62 | +p... |
| 63 | + |
| 64 | +SQL> |
| 65 | +SQL> exec dbms_lock.sleep(2); |
| 66 | + |
| 67 | +PL/SQL procedure successfully completed. |
| 68 | + |
| 69 | +SQL> exec dbms_stats.gather_table_stats(user,'stale_test1') |
| 70 | + |
| 71 | +PL/SQL procedure successfully completed. |
| 72 | + |
| 73 | +SQL> |
| 74 | +SQL> PROMPT But even though the stats were not stale, statistics have been re-gathered |
| 75 | +But even though the stats were not stale, statistics have been re-gathered |
| 76 | +SQL> PROMPT You can see this because the LAST_ANALYZED time has changed since we last looked (above) |
| 77 | +You can see this because the LAST_ANALYZED time has changed since we last looked (above) |
| 78 | +SQL> PROMPT |
| 79 | + |
| 80 | +SQL> select table_name,last_analyzed,stale_stats |
| 81 | + 2 from user_tab_statistics |
| 82 | + 3 where table_name in ('STALE_TEST1') |
| 83 | + 4 order by 1,2; |
| 84 | + |
| 85 | +TABLE_NAME LAST_ANALYZED STA |
| 86 | +------------------------- ------------------- --- |
| 87 | +STALE_TEST1 07:22:43 2018-03-16 NO |
| 88 | + |
| 89 | +SQL> |
| 90 | +SQL> pause p... |
| 91 | +p... |
| 92 | + |
| 93 | +SQL> |
| 94 | +SQL> DECLARE |
| 95 | + 2 filter_lst DBMS_STATS.OBJECTTAB := DBMS_STATS.OBJECTTAB(); |
| 96 | + 3 BEGIN |
| 97 | + 4 filter_lst.extend(1); |
| 98 | + 5 filter_lst(1).ownname := user; |
| 99 | + 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 / |
| 103 | + |
| 104 | +PL/SQL procedure successfully completed. |
| 105 | + |
| 106 | +SQL> |
| 107 | +SQL> exec dbms_lock.sleep(2); |
| 108 | + |
| 109 | +PL/SQL procedure successfully completed. |
| 110 | + |
| 111 | +SQL> PROMPT |
| 112 | + |
| 113 | +SQL> PROMPT We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , options=>'gather auto') |
| 114 | +We used dbms_stats.gather_schema_stats(obj_filter_list=> ... , options=>'gather auto') |
| 115 | +SQL> PROMPT |
| 116 | + |
| 117 | +SQL> PROMPT This time the non-stale table have been skipped |
| 118 | +This time the non-stale table have been skipped |
| 119 | +SQL> PROMPT and statistics have only been gathered where there are stale stats. |
| 120 | +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. |
| 123 | +SQL> select table_name,last_analyzed,stale_stats |
| 124 | + 2 from user_tab_statistics |
| 125 | + 3 where table_name in ('STALE_TEST1') |
| 126 | + 4 order by 1,2; |
| 127 | + |
| 128 | +TABLE_NAME LAST_ANALYZED STA |
| 129 | +------------------------- ------------------- --- |
| 130 | +STALE_TEST1 07:22:43 2018-03-16 NO |
| 131 | + |
| 132 | +SQL> |
| 133 | +SQL> |
| 134 | +SQL> spool off |
0 commit comments