Oracleのクラスタさわってみる - kagamihogeのblogã®ç¶ãã
Oracleã®ã¯ã©ã¹ã¿ã®ä½¿ç¨ä¾ã§è¯ãè¦ãããã®ã¯ã2ã¤ä»¥ä¸ã®ãã¼ãã«ãçµã³ã¤ããå¤éã¯ã©ã¹ã¿ãå¤ãããã ããå¥ã«1ã¤ã®ã¯ã©ã¹ã¿ã«1ã¤ã®ã¯ã©ã¹ã¿å表ããå ¥ããªãã¦ãåé¡ã¯ç¡ãããã®ã¨ãåããããã¡ãªããã¨ãã¦ãã¯ã©ã¹ã¿ãã¼ã§è¨å®ããåå¤ãåä¸ã®è¡ã¯ä¸ç®æã«ã¾ã¨ããããããããã®åå¤ã®è¡ãã¾ã¨ãã¦åãåºãæä½ã¯é常ãã¼ãã«ããæå©ã«ãªãããºã§ããããã®ã¨ã³ããªã§ã¯ãã®ãã¨ã確èªããã
ç°å¢
- Oracle Database Express Edition 11g Release 2ãCentOS 6.4 x86_64ä¸ã§åä½
- Oracle SQL Developer 4.0
- SQL*Plus: Release 11.2.0.2.0 Production
æºå
ã¯ã©ã¹ã¿
ã¯ã©ã¹ã¿ã®ä½æ
DROP CLUSTER emp_cluster INCLUDING TABLES; CREATE CLUSTER emp_cluster (deptno INTEGER);
ã¯ã©ã¹ã¿å表ã®ä½æãã¯ã©ã¹ã¿ã«ã¯ãdeptnoãã¯ã©ã¹ã¿ãã¼ã«ãã表ã1ã¤ããä½ããªãã
CREATE TABLE c_emp ( empno INTEGER, ename VARCHAR2(10), deptno INTEGER ) CLUSTER emp_cluster (deptno);
ã¯ã©ã¹ã¿ç´¢å¼ã®ä½æ
CREATE INDEX emp_cluster_index ON CLUSTER emp_cluster;
ãã¼ã¿ã®ä½æ
INSERT INTO c_emp(empno, ename, deptno) SELECT ROWNUM, dbms_random.string('X', 10), ceil(ROWNUM/10000) FROM (SELECT ROWNUM FROM all_catalog WHERE ROWNUM <= 1000), (SELECT ROWNUM FROM all_catalog WHERE ROWNUM <= 1000); COMMIT;
é常
ãã¼ãã«ãä½ãã
CREATE TABLE n_emp ( empno INTEGER, ename VARCHAR2(10), deptno INTEGER );
ãã¼ã¿ãå ¥ããã
INSERT INTO n_emp(empno, ename, deptno) SELECT ROWNUM, dbms_random.string('X', 10), ceil(ROWNUM/10000) FROM (SELECT ROWNUM FROM all_catalog WHERE ROWNUM <= 1000), (SELECT ROWNUM FROM all_catalog WHERE ROWNUM <= 1000); COMMIT;
ã¤ã³ããã¯ã¹ãä½ãã
CREATE INDEX ind_n_emp_dept_no ON n_emp(deptno);
é度è¨æ¸¬ç¨ã®ã¯ã¨ãª
é度è¨æ¸¬ç¨ã®å種é¡ã®ã¯ã¨ãªãæµãåã«æ¯åãããã¡ãã£ãã·ã¥ãã¯ãªã¢ããã
ALTER SYSTEM FLUSH BUFFER_CACHE;
ç¯å²ã¹ãã£ã³ãããã¯ã¨ãªã®é度è¨æ¸¬ãªã©ãè¡ãã
ã¯ã©ã¹ã¿ç¨ã®ãã®ã
SELECT empno, ename, deptno FROM c_emp WHERE deptno <= 10;
é常ãã¼ãã«ã®ãã®ã
SELECT empno, ename, deptno FROM n_emp WHERE deptno <= 10;
é度è¨æ¸¬ã®æ¹æ³
SQL*Plusã§ä¸è¨ã®ã¯ã¨ãªãå®è¡ãçµãã£ããã¨ã®çµéæéã確èªããã
ã¾ããSQL*Plusã¯ä¸è¨ã®ãããªãã©ã¡ã¼ã¿è¨å®ããããä¸äºã¤ã¯ã¨ããããarraysizeã¯æéç縮ã®ããã«è¨å®ããï¼ã©ã®ã¦ãã©å¹æãããã®ãã¯ç¢ºèªãã¦ããªãããã©ï¼
set timing on set autotrace on set arraysize 100
çµæ
å®è¡è¨ç»ã¯ãã®ã¨ã³ããªã®æ«å°¾ã«ã¾ã¨ãã¦è¼ããã
ç¨®é¡ | æé | consistent gets | physical reads |
---|---|---|---|
ã¯ã©ã¹ã¿ | 08.20 | 1320 | 310 |
é常 | 08.28 | 2537 | 528 |
ææ³ã¨ã
å®è¡æéã¯å¤§ãã¦å¤ãããªããããã®ãããã®ãã¼ã¿éã ã¨ã¦ãã®ç°å¢ã§ã¯å·®ã¯åºãªãã®ã§è´ãæ¹ãªãã
注ç®ãã¹ãã¯ãããã¯æ°ã®æ¹ã«ããã2ã¤ã®ç¯å²ã¹ãã£ã³ãè¡ãã¯ã¨ãªã¯å ¨ãåãçµæãè¿ãã®ã ããautotraceã®ãããã¯çµ±è¨ãè¦ãã¨2åè¿ãéããè¦ãããããã®çç±ã¯2ã¤èããããã
1ã¤ç®ã¯ã¯ã©ã¹ã¿ã®ç¹æ§ã«ãããã®ãã¯ã©ã¹ã¿ãã¼ã§åä¸å¤ã¯ä¸åº¦ããæ ¼ç´ãããªãã®ã§ãåä¸åå¤ã®é¨åã«ã¤ãã¦ã¯ä¸åº¦ã ãããèªã¿è¾¼ã¾ãªãã¦æ¸ãããã®ã¨ã³ããªã§ã®deptnoãããã§ãä¾ãã°deptno=1ã¯1ä¸è¡ããããdeptno=1ã¨ãããã¼ã¿ã¯1åããæ ¼ç´ãããªãããã®ç¯ç´ãããåã ããããã¯æ°ãæ¸ãããºã§ããã
2ã¤ç®ã¯ã¢ã¯ã»ã¹ãã¹ã®å·®ã«ãããã®ãé常ãã¼ãã«ã§ã¤ã³ããã¯ã¹ã使ç¨ããç¯å²ã¹ãã£ã³ãããå ´åãã¤ã³ããã¯ã¹ã¨å®ãã¼ãã«ã®2ã¤ã®ãªãã¸ã§ã¯ãã使ãå¿ è¦ãããããã®ã¨ã³ããªã®ä¾ã§ã¯ãdeptno=1ã¨ããåã¯1ä¸è¡ãããããã¤ã³ããã¯ã¹ã1ä¸è¡å¿ è¦ã¨ãªããã¾ããrowidã§å®ãã¼ãã«ã«ã¢ã¯ã»ã¹ããå¿ è¦ãããããã®ã¨ã³ããªã§ã¯deptnoã¯é çªã«æ ¼ç´ããã¦ããããããããããã©ãã©ã®å ´åãrowidã¯ãã©ãã©ã®ãããã¯ã«ã©ã³ãã ã¢ã¯ã»ã¹ããªããã°ãªããªããªããããã§ãªãã¨ããrowidã§1ã¬ã³ã¼ããã¤åãåºããããå¾ãªãã対ãã¦ã¯ã©ã¹ã¿ã®å ´åãèªã¿è¾¼ã¿å¯¾è±¡ã®ã¯ã©ã¹ã¿ãã¼ã®ãããã¯ãè¦ã¤ãããããããã¹ãã£ã³ããã ãã§ããã
ãã®ã¨ã³ããªã®ä¾ã¯å ããã«ã¼ãã£ããªãã£åº¦ãä½ãäºãåãã£ã¦ããã®ã§ãB-Treeã¤ã³ããã¯ã¹ã«ããç¯å²ã¹ãã£ã³ã¯ã©ã®ã¿ã¡ä¸å©ã§ãããå®éãªããã£ãã¤ã¶ã¯ <= 10 ã <= 20ã«ããã¨ãããã«ã¹ãã£ã³ãé¸æãã¦ãã¾ãã対ãã¦ã¯ã©ã¹ã¿å表ã®æ¹ã¯ã<= 100ã¨å ¨ã¬ã³ã¼ãè¿ãæ¡ä»¶ã§ãã£ã¦ãã¾ã ç¯å²ã¹ãã£ã³ãé¸æãããã³ã¹ãçã«ã¯ããããã軽ãè¦ç©ãã£ã¦ãæ§ããªããã¨ãããã¨ãªãã ããã
ãã®æ¹æ³ã®ãã¡ãªããã¯ãinsert/update/deleteã«ãããããã©ãããã®ã§è©¦ãã¦ããªãããããããã決ããããå ´æã«è¡ãé ç½®ããªããã°ãªããªãã®ã§ãã©ãããã£ã¦ããããæä½ã¯ä¸å©ã«ãªããããå¾ãªãããºã§ãããéãè¨ãã°ãããããã¡ãªãããè¦æã®ä¸ã§æ¤ç´¢å¹çãåããããããã¯æ¿å ¥æ´æ°åé¤ãå ¨ãçºçããªãã®ãªãã°ãã¡ãªããã¯äºå®ä¸åå¨ããªãã®ã§ãé©ç¨ã®å¯è½æ§ãåºã¦ããã
å®è¡è¨ç»
ã¯ã©ã¹ã¿
------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time | ------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 104K| 1945K| 12 (0)|00:00:01 | | 1 | TABLE ACCESS CLUSTER| C_EMP | 104K| 1945K| 12 (0)|00:00:01 | |* 2 | INDEX RANGE SCAN | EMP_CLUSTER_INDEX | 1 | | 1 (0)|00:00:01 | ------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("DEPTNO"<=10)
é常
------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 102K| 1893K| 640 (1)| 00:00:08 | | 1 | TABLE ACCESS BY INDEX ROWID| N_EMP | 102K| 1893K| 640 (1)| 00:00:08 | |* 2 | INDEX RANGE SCAN | IDX_N_EMP_DEPTNO | 102K| | 204 (1)| 00:00:03 | ------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("DEPTNO"<=10)