create table tset as select * from dba_objects;
select count(*) from tset;
select table_name,blocks,empty_blocks from dba_tables
where table_name=’TSET’;
select segment_name,bytes,blocks,extents from dba_segments
where segment_name=’TSET’;
问题来了,从dba_tables查询的blocks是空的,不按常理出牌啊~~什么鬼,什么鬼
select table_name,blocks,empty_blocks,last_analyzed from dba_tables
where table_name=’TSET’;
last_analyzed是分析的时间,为空值表示没有分析,所以执行语句分析下看看
analyze table tset compute statistics;
1071+80=1151
好像还少一个blocks,不是好像,就是少一个block。(先放这吧,不确定能找到为什么)。
以上是我发现dba_tables和dba_segments的blocks数量不一致后查询网络得出的;
大概个人总结以下:
1.dba_segments中的blocks对应的是dba_tables中的blocks+empty_blocks
2.
The dba_tables view describes a "logical" structure whiledba_segments describes the "physical" data segment, like a data file.
Also, columns like "blocks" are different between dba_tables and dba_segments. In dba_tables, the "blocks" are calculated when you run dbms_stats, while indba_segments, "blocks" is the actual number of blocks used by the object on disk.
(不解释,解释不了,我感觉只是感觉理解了),附上链接:http://www.dba-oracle.com/t_difference_dba_tables_dba_segments.htm
oracle社区里有个不是使用CTAS创建表来说明dba_segments和dba_tables不一致的问题,我重复一遍吧:
1. create table tset1 as select * from dba_objects where 1=0;
select segment_name,bytes,blocks,extents from dba_segments
where segment_name=’TSET1’;
插播:
TSET1表的行数为0;默认分配一个extent,一个extent=8 blocks,一个block=8k(65536/1024/8)
oracle 11g不是延迟段分配的吗(默认)?
好吧,先不管了,下次再说吧,插播到此结束。
2.select table_name,blocks,empty_blocks from dba_tables where table_name=’TSET1’;
analyze table tset1 compute statistics;
select table_name,blocks,empty_blocks from dba_tables where table_name=’TSET1’;
3.insert into tset1 select * from dba_objects;
commit;
4. select segment_name,bytes,blocks,extents from dba_segments
where segment_name=’TSET1’;
select table_name,blocks,empty_blocks from dba_tables
where table_name=’TSET1’;
analyze table tset1 comput statistics;
select table_name,blocks,empty_blocks from dba_tables
where table_name=’TSET1’;
1068+83=1151,还是不等于1152
附上oracle社区的链接,上面的测试结果是相等的哦!
https://community.oracle.com/thread/582356?start=0&tstart=0