今天终于看懂了oracle的索引聚簇表
公司内部下午培训了oracle的表类型。当讲到索引聚簇表时我犯了两个错误
1、创建聚簇语句
SQL> create cluster emp_dept_cluster
2 ( deptno number(2) )
3 size 1024
4 /
其中的size 1024 我当时以为是创建的聚簇的总大小。回来看了一下oracle文档和网上的相关说明发现实际的含义是
“与每个聚簇键值关联大约1024字节的数据”。理解这句话之前还要更正一下早期的错误理解。之前我以为聚簇表只是将
相关联的键值存储到聚簇中,其他字段仍然存储到heap中,其实正确的含义应该是相关的多表的所有列都存储到聚簇中。
这样我们就可以理解size字段的含义了:除了键值之外,其他与键值关联的数据最多使用size大小的空间。这样我们当然
也可以知道每个block上最多能存放多少个聚簇键了。
Specify the amount of space in bytes reserved to store all rows with the same cluster key value or the same hash value. This space determines the maximum number of cluster or hash values stored in a data block. IfSIZE
is not a divisor of the data block size, then Oracle Database uses the next largest divisor. If SIZE
is larger than the data block size, then the database uses the operating system block size, reserving at least one data block for each cluster or hash value.
The database also considers the length of the cluster key when determining how much space to reserve for the rows having a cluster key value. Larger cluster keys require larger sizes. To see the actual size, query the KEY_SIZE
column of the USER_CLUSTERS
data dictionary view. (This value does not apply to hash clusters, because hash values are not actually stored in the cluster.)
If you omit this parameter, then the database reserves one data block for each cluster key value or hash value.
2、创建聚簇表语句
SQL> create table emp
2 ( empno number primary key,
3 ename varchar2(10),
4 job varchar2(9),
5 mgr number,
6 hiredate date,
7 sal number,
8 comm number,
9 deptno number(2) constraint emp_fk references dept(deptno)
10 )
11 cluster emp_dept_cluster(deptno)
12 /
其中cluster emp_dept_cluster(deptno)的deptno是指表emp中的deptno还是值聚簇中的deptno呢?
我当时以为是聚簇中的deptno,回来在数据库中测试后发现是表中的emp字段。
还是学习的不扎实啊。。。。。。。。。。。。。。。。。。