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社區的鏈接,上面的測試結果是相等的哦!