zoukankan      html  css  js  c++  java
  • Oracle表介绍--簇表

    簇和簇表
     
        簇其实就是一组表,是一组共享相同数据块的多个表组成。 将经常一起使用的表组合在一起成簇可以提高处理效率。
     
        在一个簇中的表就叫做簇表。建立顺序是:簇→簇表→数据→簇索引
     
        1、创建簇的 格式
     
        CREATE CLUSTER cluster_name
        (column date_type [,column datatype]...)
        [PCTUSED 40 | integer] [PCTFREE 10 | integer]
        [SIZE integer]
        [INITRANS 1 | integer] [MAXTRANS 255 | integer]
        [TABLESPACE tablespace]
        [STORAGE storage]
     
        SIZE:指定估计平均簇键,以及与其相关的行所需的字节数。
     
        2、创建簇
     

        create cluster my_clu (deptno number )

        pctused 60

        pctfree 10

        size 1024

        tablespace users

        storage (

           initial 128 k

           next 128 k

           minextents 2

           maxextents 20

        );

     
        3、创建簇表
     

        create table t1_dept(

          deptno number ,

          dname varchar2 ( 20 )

        )

        cluster my_clu(deptno);

       

        create table t1_emp(

          empno number ,

          ename varchar2 ( 20 ),

          birth_date date ,

          deptno number

        )

        cluster my_clu(deptno);

     
        4、为簇创建索引
     

        create index clu_index on cluster my_clu;

     
        注:若不创建索引,则在插入数据时报错:ORA-02032: clustered tables cannot be used before the cluster index is built
     
     
    管理簇
     
        使用ALTER修改簇属性(必须拥有ALTER ANY CLUSTER的权限)
     
        1、修改簇属性
     
        可以修改的簇属性包括:
        * PCTFREE、PCTUSED、INITRANS、MAXTRANS、STORAGE
        * 为了存储簇键值所有行所需空间的平均值SIZE
        * 默认并行度
     
        注:
        * 不能修改INITIAL和MINEXTENTS的值
        * PCTFREE、PCTUSED、SIZE参数修改后适用于所有数据块
        * INITRANS、MAXTRANS仅适用于以后分配的数据块
        * STORAGE参数修改后仅影响以后分配给簇的盘区
     
        格式:

        alter cluster my_clu

        pctused 40

     
        2、删除簇
     
        drop cluster my_clu; -- 仅适用于删除空簇
     

        drop cluster my_clu including tables ; -- 删除簇和簇表

     

        drop cluster my_clu including tables cascade constraints ;

        -- 同时删除外键约束

     
        注:簇表可以像普通表一样删除。
     
     
    散列聚簇表
     
        在簇表中,Oracle使用存储在索引中的键值来定位表中的行,而在散列聚簇表中,使用了散列函数代替了簇索引,先通过内部函数或者自定义的函数进行散列计算,然后再将计算得到的码值用于定位表中的行。创建散列簇需要用到HASHKEYS子句。
     
        1、创建散列簇
     

        create cluster my_clu_two(empno number(10) )

        pctused 70

        pctfree 10

        tablespace users

        hash is empno

        hashkeys 150 ;

     
        说明:
        * hash is 子句指明了进行散列的列,如果列是唯一的标示行,就可以将列指定为散列值
        * hashkeys 指定和限制散列函数可以产生的唯一的散列值的数量
     
        2、创建散列表
     

        create table t2_emp (

          empno number ( 10 ),

          ename varchar2 ( 20 ),

          birth_date date ,

          deptno number )

        cluster my_clu_two(empno);

     
        注意:
        * 必须设置数值的精度(具体原因不详)
        * 散列簇不能也不用创建索引
        * 散列簇不能ALTER:size、hashkeys、hash is参数
  • 相关阅读:
    epoll 使用详解
    STL 较详尽总结
    可视化对比排序算法
    统治世界的十大算法
    Vector Demo
    Git远程操作(附重要原理图)
    Wireshark(五):TCP窗口与拥塞处理
    Wireshark(四):网络性能排查之TCP重传与重复ACK
    Wireshark(三):应用Wireshark IO图形工具分析数据流
    Wireshark(二):应用Wireshark观察基本网络协议
  • 原文地址:https://www.cnblogs.com/edwardsun/p/3484017.html
Copyright © 2011-2022 走看看