Download presentation
Presentation is loading. Please wait.
1
Using Clusters and Index-Organized Tables
2
Objectives Creating and maintaining clusters
Using index-organized tables Retrieving information about clusters and tables from the data dictionary
3
Distribution of Rows Within a Table
Cluster Index-organized table Ordering of Rows Random Grouped Ordered
4
Clusters Unclustered ORD and ITEM tables Clustered ORD and ITEM tables
ORD_NO PROD QTY 101 A 102 A 102 G 102 N 101 A 101 W ORD_NO ORD_DT CUST_CD JAN R01 JAN N45 Cluster Key (ORD_NO) 101 ORD_DT CUST_CD 05-JAN-97 R01 PROD QTY A A W ORD_DT CUST_CD 07-JAN-97 N45 A G N Unclustered ORD and ITEM tables Clustered ORD and ITEM tables
5
Cluster Types Index cluster Hash cluster Hash function
6
Creating Index Clusters
. Create a cluster. . Create a cluster index. CREATE CLUSTER scott.ord_clu (ord_no NUMBER(3)) SIZE 200 TABLESPACE DATA01 STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0); CREATE INDEX scott.ord_clu_idx ON CLUSTER scott.ord_clu TABLESPACE INDX01 STORAGE(INITIAL 1M NEXT 1M PCTINCREASE 0);
7
Creating Index Clusters
. Create tables in the cluster. CREATE TABLE scott.ord (ord_no NUMBER(3) CONSTRAINT ord_pk PRIMARY KEY, ord_dt DATE, cust_cd VARCHAR2(3)) CLUSTER scott.ord_clu(ord_no); CREATE TABLE scott.item (ord_no NUMBER(3) CONSTRAINT item_ord_fk REFERENCES scott.ord, prod VARCHAR2(5), qty NUMBER(3), CONSTRAINT item_pk PRIMARY KEY(ord_no,prod)) CLUSTER scott.ord_clu(ord_no);
8
Creating Hash Clusters
. Create a cluster. . Create tables in a cluster. CREATE CLUSTER scott.off_clu (country VARCHAR2(2),postcode VARCHAR2(8)) SIZE 500 HASHKEYS 1000 TABLESPACE DATA01 STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0); CREATE TABLE scott.office( office_cd NUMBER(3), cost_ctr NUMBER(3), country VARCHAR2(2), postcode VARCHAR2(8)) CLUSTER scott.off_clu(country,postcode);
9
Parameters Specific to Hash Clusters
HASHKEYS: Number of key values HASH IS: Optional user-defined hash function Key 21 Key 12 Key 11 Key 1 Key 2 Key 3 Key 22 Overflow block Preallocated blocks
10
Dropping Clusters Use INCLUDING TABLES to drop tables and cluster
or drop tables before dropping cluster. DROP CLUSTER scott.ord_clu INCLUDING TABLES; DROP TABLE scott.ord; DROP TABLE scott.item; DROP CLUSTER scott.ord_clu;
11
Index-Organized Tables
Indexed access on table Accessing index- organized table ROWID Non-key columns Key column Row header
12
Creating Index-Organized Tables
CREATE TABLE scott.sales ( office_cd NUMBER(3), qtr_end DATE, revenue NUMBER(10,2), review VARCHAR2(1000), CONSTRAINT sales_pk PRIMARY KEY(office_code, qtr_end)) ORGANIZATION INDEX TABLESPACE data01 PCTTHRESHOLD 20 OVERFLOW TABLESPACE data02;
13
Summary Identifying situations where clusters are useful
Using index-organized tables
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.