今天终于看懂了oracle的索引聚簇表

今天终于看懂了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上最多能存放多少个聚簇键了。

 

SIZE

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字段。

 还是学习的不扎实啊。。。。。。。。。。。。。。。。。。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值