Oracle: Importing and exporting optimizer statistics with DBMS_STATS
Creating a stat table
In order to be able to export optimizer statistics, a stat table is needed. Such a table can be created with dbms_stats.create_stat_table:
begin
dbms_stats.create_stat_table (
ownname => user,
stattab =>'TQ84_STATS',
-- tblspace => -- use default tablespace
global_temporary => false -- create heap table. Default is global temporary table.
);
end;
/
These are the columns of the stat table:
desc tq84_stats
Name Null? Type
------- ----- ---------------------------
STATID VARCHAR2(128)
TYPE CHAR(1)
VERSION NUMBER
FLAGS NUMBER
C1 VARCHAR2(128)
C2 VARCHAR2(128)
C3 VARCHAR2(128)
C4 VARCHAR2(128)
C5 VARCHAR2(128)
C6 VARCHAR2(128)
N1 NUMBER
N2 NUMBER
N3 NUMBER
N4 NUMBER
N5 NUMBER
N6 NUMBER
N7 NUMBER
N8 NUMBER
N9 NUMBER
N10 NUMBER
N11 NUMBER
N12 NUMBER
N13 NUMBER
D1 DATE
T1 TIMESTAMP(6) WITH TIME ZONE
R1 RAW(1000 BYTE)
R2 RAW(1000 BYTE)
R3 RAW(1000 BYTE)
CH1 VARCHAR2(1000)
CL1 CLOB
BL1 BLOB
The imported statistics are found in the following data dictionary views:
select * from user_tab_statistics where table_name = 'TQ84_IX';
select * from user_ind_statistics where table_name = 'TQ84_IX';
select * from user_tab_col_statistics where table_name = 'TQ84_IX';
Dropping the stat table
The stat table is not used anymore. It can be dropped: