达梦
创建CREATE_STAT_TABLE 统计信息表
PROCEDURE CREATE_STAT_TABLE (
STATOWN VARCHAR(128),
STATTAB VARCHAR(128),
TABLESPACE VARCHAR(128) DEFAULT NULL,
GLOBAL_TEMPORARY BOOLEAN DEFAULT FALSE
);
创建普通表的对应系统表的列名字段包括以下:
OWNER TABLE_NAME TABLESPACE_NAME CLUSTER_NAME IOT_NAME STATUS PCT_FREE PCT_USED INI_TRANS MAX_TRANS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE FREELISTS FREELIST_GROUPS LOGGING BACKED_UP NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN AVG_SPACE_FREELIST_BLOCKS NUM_FREELIST_BLOCKS DEGREE INSTANCES CACHE TABLE_LOCK SAMPLE_SIZE LAST_ANALYZED PARTITIONED IOT_TYPE TEMPORARY SECONDARY NESTED BUFFER_POOL FLASH_CACHE CELL_FLASH_CACHE ROW_MOVEMENT GLOBAL_STATS USER_STATS DURATION SKIP_CORRUPT MONITORING CLUSTER_OWNER DEPENDENCIES COMPRESSION COMPRESS_FOR DROPPED READ_ONLY SEGMENT_CREATED RESULT_CACHE LONG_ROW
可创建指定用户下的统计信息表。
select * from SU.STAT$_TEST_N1_SU;
可以得出创建的统计信息表的列名字段:
STATID OWNNAME TABNAME NAME T_FLAG T_TOTAL N_SAMPLE N_DISTINCT N_NULL V_MIN V_MAX BLEVEL N_LEAF_PAGES N_LEAF_USED_PAGES CLUSTER_FACTOR N_BUCKETS DATA COL_AVG_LEN LAST_GATHERED INFO1 INFO2
其中收集表信息时使用的列字段是 T_TOTAL N_LEAF_PAGES N_LEAF_USED_PAGES
其中总行数可以在表对应的系统表记录的属性中取到
select * from all_tables where table_name = ‘TT_1’;
把目标表的统计信息导出到指定统计信息表中。dbms_stats.EXPORT_TABLE_STATS(‘SYSDBA’,‘TT_1’,NULL,‘TEST’);
select * from STAT$_TEST;查询创建的统计信息表信息
Oracle
创建CREATE_STAT_TABLE 统计信息表
指定用户和表名,会创建到指定用户下
可以得出创建的统计信息表的列名字段:
C1 TABLE_NAME C5 OWNERNAME N1 NUM_ROWS N2 BLOCKS (推测)
Oracle不支持达梦中 table_stats_show存储过程,只能通过导入统计信息表查看。
创建普通表的对应系统表的列名字段包括以下:
OWNER
TABLE_NAME
TABLESPACE_NAME
CLUSTER_NAME
IOT_NAME
STATUS PCT_FREE PCT_USED INI_TRANS MAX_TRANS INITIAL_EXTENT
NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE FREELISTS FREELIST_GROUPS
LOGGIN BA NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN
AVG_SPACE_FREELIST_BLOCKS NUM_FREELIST_BLOCKS
DEGREE
INSTANCES
CACHE TABLE_LOCK SAMPLE_SIZE
LAST_ANALYZED PARTIT IOT_TYPE TE SE NESTED BUFFER_POOL
FLASH_CACHE CELL_FLASH_CAC ROW_MOVEMENT GLOBAL USER_S
DURATION SKIP_CORRUPT MONITO
CLUSTER_OWNER
DEPENDENCIES COMPRESSION
COMPRESS_FOR DROPPE READ_O
SEGMEN RESULT_CACHE CLUSTE ACTIVITY_TRACKING
DML_TIMESTAMP HAS_ID CONTAI
INMEMORY INMEMORY_PRIORIT INMEMORY_DISTRIBUTE
INMEMORY_COMPRESSION INMEMORY_DUPLICATE
DEFAULT_COLLATION
DU SH EXTERN CELLMEMORY
CONTAI CONTAI
EXTEND EXTEND
INMEMORY_SERVICE INMEMORY_SERVICE_NAME
CONTAI
对于统计字段,新建表后,插入数据之前都为空值,执行gather进行信息收集会更新值。
例子:
SQL> select owner,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from all_tables where table_name = ‘T1’;
OWNER | NUM_ROWS | BLOCKS | EMPTY_BLOCKS |
---|---|---|---|
C##XFJ | 0 | 5 | 0 |
C##SU |
SQL> call dbms_stats.GATHER_TABLE_STATS(‘c##su’,‘T1’);
Call completed.
SQL> select owner,NUM_ROWS,BLOCKS,EMPTY_BLOCKS from all_tables where table_name = ‘T1’;
OWNER | NUM_ROWS | BLOCKS | EMPTY_BLOCKS |
---|---|---|---|
C##XFJ | 0 | 5 | 0 |
C##SU | 1 | 5 | 0 |
把目标表的统计信息导出到指定统计信息表中。
call dbms_stats.EXPORT_TABLE_STATS(‘c##su’,‘T1’,NULL,‘TT_1’);
Create procedure f1
Begin
Str_sql := ‘select :1 from systables where tabname = ‘b1’’;
Execute immediate str_sql into b using a;
End;
/