Oracle索引聚簇表的數(shù)據(jù)加載的實(shí)操
以下的文章主要是對(duì)Oracle索引聚簇表的數(shù)據(jù)加載的詳細(xì)介紹 ,如果你對(duì)Oracle索引聚簇表的數(shù)據(jù)加載的實(shí)際操作不是很了解的話,以下的文章通過(guò)一些相關(guān)的實(shí)用方案來(lái)對(duì)其進(jìn)行詳細(xì)介紹,希望你會(huì)有所收獲。
加載數(shù)據(jù)
向Oracle聚簇索引表中加載數(shù)據(jù)是個(gè)很講究的事情,處理方法不對(duì),會(huì)使得聚簇的功能發(fā)揮不完全,降低查詢性能。
方法1:
首先,我增加一個(gè)很大的列char(1000),加這個(gè)列是為了讓EMP行遠(yuǎn)遠(yuǎn)大于現(xiàn)在的大小。使得一個(gè)1024的聚簇?zé)o法存儲(chǔ)一行記錄。不能加varchar2(1000),因?yàn)镺racle對(duì)varchar2存儲(chǔ)的原則是能省就省,如果數(shù)據(jù)數(shù)據(jù)不到1000,不會(huì)分配1000的空間的。char則是有多少用多少。呵呵。
- SQL> begin
- for x in ( select * from scott.dept )
- loop
- insert into dept
- values ( x.deptno, x.dname, x.loc );
- insert into emp
- select *
- from scott.emp 9 where deptno = x.deptno;
- end loop;
- end;
- /
- begin
- *
第1行出現(xiàn)錯(cuò)誤:ORA-02032:聚簇表無(wú)法在簇索引建立之前使用,ORA-06512:在line 4
- SQL> create index emp_dept_cluster_idx
- on cluster emp_dept_cluster
- ;
索引已創(chuàng)建。
- SQL> alter table emp disable constraint emp_fk;
表已更改。
- SQL> truncate cluster emp_dept_cluster;
Oracle索引聚簇表已截?cái)唷?/p>
- SQL> alter table emp enable constraint emp_fk;
表已更改。
- SQL> alter table emp add data char(1000);
表已更改。
上面的執(zhí)行錯(cuò)誤說(shuō)明聚簇表無(wú)法在簇索引建立之前使用。首先我們通過(guò)先加載emp表,后加載dept表的方式。
- SQL> insert into dept
- select * from scott.dept;
已創(chuàng)建4行。
- SQL> insert into emp
- select emp.*, '*' from scott.emp
已創(chuàng)建14行。
然后做一個(gè)查詢,通過(guò)dbms_rowid.rowid_block_number可以查看此數(shù)據(jù)所在的BLOCK ID,如果dept和emp存儲(chǔ)的行數(shù)據(jù)不是一個(gè)BLOCK ID ,則標(biāo)記一個(gè)'*'.查詢結(jié)果如下:
- SQL> select dept_blk, emp_blk, 2 case when dept_blk <>
emp_blk then '*' end flag,- deptno
- from (
- select dbms_rowid.rowid_block_number(dept.rowid)
dept_blk, 6 dbms_rowid.rowid_block_number(emp.rowid)
emp_blk, 7 dept.deptno 8 from emp, dept 9 where emp.deptno
= dept.deptno- )
- order by deptno
- /
- DEPT_BLK EMP_BLK F DEPTNO
- 85 86 * 10
- 85 86 * 10
- 85 87 * 10
- 85 85 20
- 85 87 * 20
- 85 86 * 20
- 85 85 20
- 85 86 * 20
- 85 85 30
- 85 86 * 30
- 85 85 30
- DEPT_BLK EMP_BLK F DEPTNO
- 85 86 * 30
- 85 85 30
- 85 85 30
已選擇14行。
我們發(fā)現(xiàn),通過(guò)先插入emp數(shù)據(jù),再插入dept數(shù)據(jù),導(dǎo)致大部分的emp和dept的數(shù)據(jù)都不在一個(gè)block上,這不是我們使用索引Oracle聚簇表索引的目的。
【編輯推薦】
























