Decode360's Blog

          業(yè)精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
            397 隨筆 :: 33 文章 :: 29 評(píng)論 :: 0 Trackbacks
          簇和簇表
          ?
          ??? 簇其實(shí)就是一組表,是一組共享相同數(shù)據(jù)塊的多個(gè)表組成。 將經(jīng)常一起使用的表組合在一起成簇可以提高處理效率。
          ?
          ??? 在一個(gè)簇中的表就叫做簇表。建立順序是:簇→簇表→數(shù)據(jù)→簇索引
          ?
          ??? 1、創(chuàng)建簇的 格式
          ?
          ??? 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:指定估計(jì)平均簇鍵,以及與其相關(guān)的行所需的字節(jié)數(shù)。
          ?
          ??? 2、創(chuàng)建簇
          ?

          ??? 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、創(chuàng)建簇表
          ?

          ??? 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、為簇創(chuàng)建索引
          ?

          ??? create index clu_index on cluster my_clu;

          ?
          ??? 注:若不創(chuàng)建索引,則在插入數(shù)據(jù)時(shí)報(bào)錯(cuò):ORA-02032: clustered tables cannot be used before the cluster index is built
          ?
          ?
          管理簇
          ?
          ??? 使用ALTER修改簇屬性(必須擁有ALTER ANY CLUSTER的權(quán)限)
          ?
          ??? 1、修改簇屬性
          ?
          ??? 可以修改的簇屬性包括:
          ??? * PCTFREE、PCTUSED、INITRANS、MAXTRANS、STORAGE
          ??? * 為了存儲(chǔ)簇鍵值所有行所需空間的平均值SIZE
          ??? * 默認(rèn)并行度
          ?
          ??? 注:
          ??? * 不能修改INITIAL和MINEXTENTS的值
          ??? * PCTFREE、PCTUSED、SIZE參數(shù)修改后適用于所有數(shù)據(jù)塊
          ??? * INITRANS、MAXTRANS僅適用于以后分配的數(shù)據(jù)塊
          ??? * STORAGE參數(shù)修改后僅影響以后分配給簇的盤區(qū)
          ?
          ??? 格式:

          ??? 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 ;

          ??? -- 同時(shí)刪除外鍵約束

          ?
          ?? 注:簇表可以像普通表一樣刪除。
          ?
          ?
          散列聚簇表
          ?
          ??? 在簇表中,Oracle使用存儲(chǔ)在索引中的鍵值來(lái)定位表中的行,而在散列聚簇表中,使用了散列函數(shù)代替了簇索引,先通過(guò)內(nèi)部函數(shù)或者自定義的函數(shù)進(jìn)行散列計(jì)算,然后再將計(jì)算得到的碼值用于定位表中的行。創(chuàng)建散列簇需要用到HASHKEYS子句。
          ?
          ??? 1、創(chuàng)建散列簇
          ?

          ??? create cluster my_clu_two(empno number(10) )

          ??? pctused 70

          ??? pctfree 10

          ??? tablespace users

          ??? hash is empno

          ??? hashkeys 150 ;

          ?
          ??? 說(shuō)明:
          ??? * hash is 子句指明了進(jìn)行散列的列,如果列是唯一的標(biāo)示行,就可以將列指定為散列值
          ??? * hashkeys 指定和限制散列函數(shù)可以產(chǎn)生的唯一的散列值的數(shù)量
          ?
          ??? 2、創(chuàng)建散列表
          ?

          ??? create table t2_emp (

          ??? ? empno number ( 10 ),

          ??? ? ename varchar2 ( 20 ),

          ??? ? birth_date date ,

          ??? ? deptno number )

          ??? cluster my_clu_two(empno);

          ?
          ??? 注意:
          ??? * 必須設(shè)置數(shù)值的精度(具體原因不詳)
          ??? * 散列簇不能也不用創(chuàng)建索引
          ??? * 散列簇不能ALTER:size、hashkeys、hash is參數(shù)
          ?
          ?
          ?
          posted on 2008-10-19 21:49 decode360 閱讀(153) 評(píng)論(0)  編輯  收藏 所屬分類: 07.Oracle
          主站蜘蛛池模板: 增城市| 贺兰县| 前郭尔| 石首市| 高淳县| 山东| 潢川县| 习水县| 灌云县| 合江县| 萨迦县| 新源县| 泽普县| 沿河| 固镇县| 萝北县| 石家庄市| 韶山市| 夹江县| 怀宁县| 漠河县| 丹阳市| 突泉县| 沾益县| 利川市| 望都县| 贵州省| 古田县| 延安市| 舟山市| 师宗县| 鄂托克前旗| 大化| 建湖县| 梁河县| 康乐县| 无极县| 临汾市| 海宁市| 武宣县| 那坡县|