一、结论dba_segments指定表名查询到的段大小包含索引、约束、表字段数据(包含LOB字段)(1)表(不包含LOB字段)创建默认分配2个簇,1个簇用于存放表结构及字段数据,1个簇用于存放cluster类型的索引(2)创建索引默认会分配2个簇,用于存放normal索引数据(3)创建约束不会额外分配空间,除非是主键或唯一约束(4)添加LOB字段默认分配2个簇,用于存放lob字段数据(5)表(包含LOB字段)创建默认分配4个簇,1个簇用于存放表结构及字段数据,1个簇用于存放cluster类型的索引,2和簇用于存放lob字段数据
二、测试过程(一)创建测试表,查看初始大小create table test01(id number,name varchar2(10));SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name='TEST01';OWNERSEGMENT_NAME BYTESBLOCKSEXTENTSINITIAL_EXTENT------ ------------ -------------------- -------------------- -------------------- --------------------SYSDBA TEST0120971526421048576SQL> select owner,index_name,index_type,initial_extent from dba_indexes where owner='SYSDBA' and table_name='TEST01';OWNERINDEX_NAMEINDEX_TYPE INITIAL_EXTENT------ ------------- ---------- --------------SYSDBA INDEX33566761 CLUSTER1SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name in('INDEX33566761');未选定行(二)添加索引,查看空间变化create index idx_test01_name on test01(name);SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name='TEST01';OWNER SEGMENT_NAME BYTES BLOCKS EXTENTS INITIAL_EXTENT------ ------------ -------------------- -------------------- -------------------- --------------------SYSDBA TEST01 4194304 128 4 1048576SQL> select owner,index_name,index_type,initial_extent from dba_indexes where owner='SYSDBA' and table_name='TEST01';OWNER INDEX_NAME INDEX_TYPE INITIAL_EXTENT------ --------------- ---------- --------------SYSDBA INDEX33566761 CLUSTER 1SYSDBA IDX_TEST01_NAME NORMAL 1SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name in('INDEX33566761','IDX_TEST01_NAME');OWNER SEGMENT_NAME BYTES BLOCKS EXTENTS INITIAL_EXTENT------ --------------- -------------------- -------------------- -------------------- --------------------SYSDBA IDX_TEST01_NAME 2097152 64 2 1048576(三)添加主键,查看空间变化alter table test01 add constraint pk_test01_id primary key(id);SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name='TEST01';OWNER SEGMENT_NAME BYTES BLOCKS EXTENTS INITIAL_EXTENT------ ------------ -------------------- -------------------- -------------------- --------------------SYSDBA TEST01 6291456 192 6 1048576SQL> select owner,index_name,index_type,initial_extent from dba_indexes where owner='SYSDBA' and table_name='TEST01';OWNER INDEX_NAME INDEX_TYPE INITIAL_EXTENT------ --------------- ---------- --------------SYSDBA INDEX33566761 CLUSTER 1SYSDBA INDEX33566763 NORMAL 1SYSDBA IDX_TEST01_NAME NORMAL 1SQL> select constraint_name,constraint_type,status,index_name from dba_constraints where owner='SYSDBA' and table_name='TEST01';CONSTRAINT_NAME CONSTRAINT_TYPE STATUS INDEX_NAME--------------- --------------- ------- -------------PK_TEST01_ID P ENABLED INDEX33566763SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name in('INDEX33566761','IDX_TEST01_NAME','INDEX33566763');OWNER SEGMENT_NAME BYTES BLOCKS EXTENTS INITIAL_EXTENT------ --------------- -------------------- -------------------- -------------------- --------------------SYSDBA IDX_TEST01_NAME 2097152 64 2 1048576SYSDBA INDEX33566763 2097152 64 2 1048576(四)创建约束,查看空间变化alter table test01 add constraint ck_test01_id check(id>=1);SQL> select owner,segment_name,bytes,blocks,extents,initial_extent from dba_segments where owner='SYSDBA' and segment_name='TEST01';OWNER SEGMENT_NAME BYTES BLOCKS EXTENTS INITIAL_EXTENT------ ------------ -------------------- -------------------- -------------------- --------------------SYSDBA TEST01 6291456 192 6 1048576SQL> select constraint_name,constraint_type,status,index_name from dba_constraints where owner='SYSDBA' and table_name='TEST01';CONSTRAINT_NAME CONSTRAINT_TYPE STATUS INDEX_NAME--------------- --------------- ------- -------------CK_TEST01_ID C ENABLED NULLPK_TEST01_ID P ENABLED INDEX33566763