プランナ統計情報クリア

(8.0.26)

drop table tab1;
create table tab1(col1 int,col2 varchar(100) );

insert into tab1 values(100,'AAA');
insert into tab1 values(200,'BBB');
insert into tab1 values(300,'CCC');
select * from tab1;

analyze table tab1;

select * from mysql.innodb_table_stats where table_name = 'tab1';
select * from mysql.innodb_index_stats where table_name = 'tab1';

-- 統計情報削除
delete from mysql.innodb_table_stats where table_name = 'tab1';
delete from mysql.innodb_index_stats where table_name = 'tab1';

 

(8.0.33)
https://yoku0825.blogspot.com/2019/05/mysql-80show-table-status.html

set information_schema_stats_expiry = 0;

(19c)

drop table tab1 purge;
create table tab1(col1 int,col2 varchar2(100) );

insert into tab1 values(1,'AAA');
insert into tab1 values(2,'BBB');
insert into tab1 values(3,'CCC');
commit;
select * from tab1;
create unique index ind1 on tab1(col1);

exec dbms_stats.gather_table_stats(user,'TAB1', method_opt =>'FOR ALL COLUMNS SIZE 100');

alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';

select * from user_tab_statistics where table_name = 'TAB1';
select NUM_ROWS, LAST_ANALYZED from user_tab_statistics where table_name = 'TAB1';

→統計削除プロシージャ実行後、データとしては残るが、NUM_ROWSやLAST_ANALYZEDはヌルとなる

select * from user_ind_statistics where table_name = 'TAB1';
select NUM_ROWS, LAST_ANALYZED from user_ind_statistics where table_name = 'TAB1';

→統計削除プロシージャ実行後、データとしては残るが、NUM_ROWSやLAST_ANALYZEDはヌルとなる

select * from user_tab_col_statistics where table_name = 'TAB1';
→統計削除プロシージャ実行後、データとして消える

select * from user_tab_histograms where table_name = 'TAB1';
→統計削除プロシージャ実行後、データとして消える


select * from user_tab_stats_history where table_name = 'TAB1';
→統計削除プロシージャ実行後、統計取得時と統計削除時の2件のエントリとなる


-- 統計情報削除
exec dbms_stats.delete_table_stats(user,'TAB1');


-- ディクショナリに自動保存される履歴を削除する場合
exec dbms_stats.purge_stats(sysdate);

DB全体が対象となる


※統計履歴リテンション確認
select DBMS_STATS.GET_STATS_HISTORY_RETENTION from dual;

※統計履歴リテンション設定
exec DBMS_STATS.ALTER_STATS_HISTORY_RETENTION(1);

 

(14)

drop table tab1;
create table tab1(col1 int,col2 varchar(100) );

insert into tab1 values(100,'AAA');
insert into tab1 values(200,'BBB');
insert into tab1 values(300,'CCC');
select * from tab1;

analyze tab1;

select * from pg_class where relname = 'tab1';
select * from pg_statistic where starelid = 'tab1'::regclass::oid;

update pg_class set relpages = 0 where relname = 'tab1';
update pg_statistic set stanumbers2 = NULL,stavalues1 = NULL where starelid = 'tab1'::regclass::oid;

 

(2019)

拡張統計に限り削除できる模様

https://docs.microsoft.com/ja-jp/sql/relational-databases/statistics/delete-statistics?view=sql-server-2017

インデックスの統計を DROP STATISTICS で削除することはできません。 インデックスが存在する限り、統計は維持されます。