Decode360's Blog

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

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 ::  :: 管理 ::
            397 隨筆 :: 33 文章 :: 29 評論 :: 0 Trackbacks
          簇和簇表
          ?
          ??? 簇其實就是一組表,是一組共享相同數據塊的多個表組成。 將經常一起使用的表組合在一起成簇可以提高處理效率。
          ?
          ??? 在一個簇中的表就叫做簇表。建立順序是:簇→簇表→數據→簇索引
          ?
          ??? 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參數
          ?
          ?
          ?
          posted on 2008-10-19 21:49 decode360 閱讀(150) 評論(0)  編輯  收藏 所屬分類: 07.Oracle
          主站蜘蛛池模板: 富源县| 望奎县| 明水县| 鄂托克前旗| 太仓市| 泗洪县| 庄浪县| 星子县| 青河县| 邵武市| 通榆县| 桃江县| 甘德县| 富阳市| 昌邑市| 邵武市| 安达市| 林甸县| 丰宁| 广平县| 图木舒克市| 咸阳市| 越西县| 绥德县| 彭泽县| 平定县| 泸西县| 怀安县| 万山特区| 绥宁县| 微博| 虎林市| 治县。| 高尔夫| 磐安县| 利津县| 郯城县| 江北区| 永平县| 旺苍县| 沙田区|