h3.클러스터 생성
create cluster emp_dept_cluster
(deptno number(2))
size 1024
/
* deptno number(2)
** 클러스터의 클러스터링 대상 컬럼은 deptno, 테이블에서의 컬럼은 deptno라고 정의될 필요는 없지만, 반드시 number(2) 컬럼이어야 함.
* size 1024
** 클러스터 키 값과 관련된 데이터는 1024 바이트 정도라고 정의. 오라클은 이것을 이용하여 각 블록에 저장할 수 있는 클러스터 키의 최대수를 계산.
** 블록 크기가 8KB라면 오라클은 한 블록에 7개의 클러스터키를 위치시킨다.
create index emp_dept_cluster_idx
on cluster emp_dept_cluster
/
create table dept
( deptno number(2) primary key,
dname varchar2(14),
loc varchar2(13)
)
cluster emp_dept_cluster(deptno)
/
create table emp
( empno number primary key,
ename varchar2(10),
job varchar2(9),
mgr number,
hiredate date,
sal number,
comm number,
deptno number(2) references dept(deptno)
)
cluster emp_dept_cluster(deptno)
/
-- 클러스터 사이즈에 모든 데이터가 들어갈 경우
insert into dept
(deptno, dname, loc)
select deptno+r, dname, loc
from scott.dept,
(select level r from dual connect by level < 10);
insert into emp
(empno, ename, job, mgr, hiredate, sal, comm, deptno)
select rownum, ename, job, mgr, hiredate, sal, comm, deptno+r
from scott.emp,
(select level r from dual connect by level < 10);
select min(count(*)), max(count(*)), avg(count(*))
from dept
group by dbms_rowid.rowid_block_number(rowid)
/
?
MIN(COUNT(*)) MAX(COUNT(*)) AVG(COUNT(*))
------------- ------------- -------------
1 7 6
1 row selected.
select *
from (select dept_blk,
emp_blk,
case
when dept_blk <> emp_blk then '*'
end flag,
deptno
from (select dbms_rowid.rowid_block_number(dept.rowid) dept_blk,
dbms_rowid.rowid_block_number(emp.rowid) emp_blk,
dept.deptno
from emp,
dept
where emp.deptno = dept.deptno ) )
where flag = '*'
order by deptno
/
no rows selected
-- 데이터가 클러스터 사이즈 보다 큰 경우
insert into dept
(deptno, dname, loc)
select deptno+r, dname, loc
from scott.dept,
(select level r from dual connect by level < 10);
insert into emp
(empno, ename, job, mgr, hiredate, sal, comm, deptno)
select rownum, ename, job, mgr, hiredate, sal, comm, deptno+r
from scott.emp,
(select level r from dual connect by level < 10),
(select level r2 from dual connect by level < 8);
select min(count(*)), max(count(*)), avg(count(*))
from dept
group by dbms_rowid.rowid_block_number(rowid)
/
MIN(COUNT(*)) MAX(COUNT(*)) AVG(COUNT(*))
------------- ------------- -------------
1 7 6
1 row selected.
select *
from (select dept_blk,
emp_blk,
case
when dept_blk <> emp_blk then '*'
end flag,
deptno
from (select dbms_rowid.rowid_block_number(dept.rowid) dept_blk,
dbms_rowid.rowid_block_number(emp.rowid) emp_blk,
dept.deptno
from emp,
dept
where emp.deptno = dept.deptno ) )
where flag = '*'
order by deptno
/
DEPT_BLK EMP_BLK F DEPTNO
---------- ---------- - ----------
11307 11338 * 12
11307 11338 * 12
11307 11338 * 12
11307 11338 * 12
11307 11338 * 12
11309 11338 * 17
11310 11339 * 19
11310 11339 * 19
11310 11339 * 19
11310 11339 * 19
11310 11339 * 19
11310 11339 * 19
11307 11338 * 22
11307 11338 * 22
11307 11338 * 22
11307 11338 * 22
11307 11338 * 22
11307 11338 * 22
11307 11338 * 22
11309 11338 * 27
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11310 11339 * 29
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11307 11338 * 32
11309 11338 * 37
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
11310 11338 * 39
46 rows selected.
-- 클러스터 사이즈 변경
-- delete table 로는 클러스터 사이즈를 변경해도 기존 블럭에는 영향을 미치지 않는다.
alter table emp modify constraints SYS_C0014799 disable;
truncate cluster emp_dept_cluster;
alter table emp modify constraints SYS_C0014799 enable;
alter cluster emp_dept_cluster
size 1200
/
insert into dept
(deptno, dname, loc)
select deptno+r, dname, loc
from scott.dept,
(select level r from dual connect by level < 10);
insert into emp
(empno, ename, job, mgr, hiredate, sal, comm, deptno)
select rownum, ename, job, mgr, hiredate, sal, comm, deptno+r
from scott.emp,
(select level r from dual connect by level < 10),
(select level r2 from dual connect by level < 8);
select min(count(*)), max(count(*)), avg(count(*))
from dept
group by dbms_rowid.rowid_block_number(rowid)
/
MIN(COUNT(*)) MAX(COUNT(*)) AVG(COUNT(*))
------------- ------------- -------------
6 6 6
1 row selected.
select *
from (select dept_blk,
emp_blk,
case
when dept_blk <> emp_blk then '*'
end flag,
deptno
from (select dbms_rowid.rowid_block_number(dept.rowid) dept_blk,
dbms_rowid.rowid_block_number(emp.rowid) emp_blk,
dept.deptno
from emp,
dept
where emp.deptno = dept.deptno ) )
where flag = '*'
order by deptno
/
no rows selected
rowid는 한 테이블 내에서만 유일한 pseudo 컬럼이다.
select rowid from emp
intersect
select rowid from dept;
......
36 rows selected.
break on cluster_name
select cluster_name, table_name
from dba_tables
where cluster_name is not null
order by 1;
CLUSTER_NAME TABLE_NAME
------------------------------ ---------------------
C_COBJ# CDEF$
CCOL$
C_FILE#_BLOCK# UET$
SEG$
C_MLOG# SLOG$
MLOG$
C_OBJ# REFCON$
NTAB$
SUBCOLTYPE$
COLTYPE$
LOB$
TAB$
CLU$
COL$
IND$
ICOL$
OPQTYPE$
ICOLDEP$
VIEWTRCOL$
LIBRARY$
ASSEMBLY$
TYPE_MISC$
ATTRCOL$
C_OBJ#_INTCOL# HISTGRM$
C_RG# RGCHILD$
RGROUP$
C_TOID_VERSION# METHOD$
ATTRIBUTE$
PARAMETER$
COLLECTION$
TYPE$
RESULT$
C_TS# TS$
FET$
C_USER# USER$
TSQ$
EMP_DEPT_CLUSTER DEPT
EMP
SMON_SCN_TO_TIME_AUX SMON_SCN_TIME
39 rows selected.