ããä¸ãä»ä¹æ¯ååºè¡¨
ãã表ååºæ以ä¸ä¼ç¹ï¼
ãã1ãæ°æ®æ¥è¯¢ï¼æ°æ®è¢«åå¨å°å¤ä¸ªæ件ä¸ï¼åå°äºI/Oè´è½½ï¼æ¥è¯¢é度æé«ã
ãã2ãæ°æ®ä¿®åªï¼ä¿ååå²æ°æ®é常ççæ³ã
ãã3ãå¤ä»½ï¼å°å¤§è¡¨çæ°æ®åæå¤ä¸ªæ件ï¼æ¹ä¾¿å¤ä»½åæ¢å¤ã
ãã4ã并è¡æ§ï¼å¯ä»¥åæ¶å表ä¸è¿è¡DMLæä½ï¼å¹¶è¡æ§æ§è½æé«ï¼åè¡¡I/Oï¼å¯ä»¥æä¸åçååºæ å°å°ç£ç以平衡I/Oï¼æ¹åæ´ä¸ªç³»ç»æ§è½ã
ãã5ãå¢å¼ºå¯ç¨æ§ï¼å¦æ表çæ个ååºåºç°æ
éï¼è¡¨å¨å
¶ä»ååºçæ°æ®ä»ç¶å¯ç¨ï¼
ãã6ãç»´æ¤æ¹ä¾¿ï¼å¦æ表çæ个ååºåºç°æ
éï¼éè¦ä¿®å¤æ°æ®ï¼åªä¿®å¤è¯¥ååºå³å¯ï¼
ãã7ãæ¹åæ¥è¯¢æ§è½ï¼å¯¹ååºå¯¹è±¡çæ¥è¯¢å¯ä»¥ä»
æç´¢èªå·±å
³å¿çååºï¼æé«æ£ç´¢é度ã
ãã8ãéè¦æ³¨æçæ¯å
å«LONGãLONGRAWæ°æ®ç±»åç表ä¸è½ååº,å¦æè¡¨æ ¼å¤§äº2Géè¦èèååºã
ããäºãååºè¡¨çç§ç±»
ãã1ãRANGE èå´ååº
ãã说æï¼é对记å½å段çå¼å¨æ个èå´ã
ããè§åï¼
ããï¼1ï¼ãæ¯ä¸ä¸ªååºé½å¿
é¡»æä¸ä¸ªVALUES LESS THENåå¥ï¼å®æå®äºä¸ä¸ªä¸å
æ¬å¨è¯¥ååºä¸çä¸éå¼ã
ããååºé®çä»»ä½å¼çäºæè
大äºè¿ä¸ªä¸éå¼çè®°å½é½ä¼è¢«å å
¥å°ä¸ä¸ä¸ªé«ä¸äºçååºä¸ã
ããï¼2ï¼ãææååºï¼é¤äºç¬¬ä¸ä¸ªï¼é½ä¼æä¸ä¸ªéå¼çä¸éå¼ï¼è¿ä¸ªå¼å°±æ¯æ¤ååºçåä¸ä¸ªååºçä¸éå¼ã
ããï¼3ï¼ãå¨æé«çååºä¸ï¼MAXVALUE被å®ä¹ãMAXVALUE代表äºä¸ä¸ªä¸ç¡®å®çå¼ãè¿ä¸ªå¼é«äºå
¶å®ååºä¸çä»»ä½ååºé®çå¼ï¼
ããä¹å¯ä»¥ç解为é«äºä»»ä½ååºä¸æå®çVALUE LESS THENçå¼ï¼åæ¶å
æ¬ç©ºå¼ãè¥ä¸æ·»å maxvalueçååºæå
¥æ°å¼ä¸æ¦è¶
è¿è®¾ç½®çæ大ä¸éä¼æ¥éã
ããä¾ä¸ï¼ædateèå´å建ååºè¡¨
ããCREATE TABLE PART_TAB_CUSTOMER_BY_RANGE
ãã(
ããCUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,
ããFIRST_NAME VARCHAR2(30) NOT NULL,
ããLAST_NAME VARCHAR2(30) NOT NULL,
ããPHONE VARCHAR2(15) NOT NULL,
ããEMAIL VARCHAR2(80),
ããSEX VARCHAR2(10),
ããSTATUS VARCHAR2(10),
ããINSERT_DATE DATE
ãã)
ããPARTITION BY RANGE (INSERT_DATE) --ææ¶é´ååº
ãã(
ããPARTITION DATE_RANGE1 VALUES LESS THAN (TO_DATE(' 2001-01-01', 'YYYY-MM-DD')) TABLESPACE part_Data1,
ããPARTITION DATE_RANGE2 VALUES LESS THAN (TO_DATE(' 2007-01-01', 'YYYY-MM-DD')) TABLESPACE part_Data2,
ããPARTITION DATE_RANGE3 VALUES LESS THAN (maxvalue) TABLESPACE part_Data3
ãã)
ããä¾äºãæç
§numberèå´ååº
ããPARTITION BY RANGE (CUSTOMER_ID) --æidååº
ãã(
ããPARTITION CUS_PART1 VALUES LESS THAN (100000) TABLESPACE part_Data1,
ããPARTITION CUS_PART2 VALUES LESS THAN (200000) TABLESPACE part_Data2,
ããPARTITION CUS_PART2 VALUES LESS THAN (maxvalue) TABLESPACE part_Data3
ãã)
ãã2ãLIST å表ååº
ãã说æï¼è¯¥ååºçç¹ç¹æ¯æåçå¼åªææé个å¼ï¼åºäºè¿æ ·çç¹ç¹æ们å¯ä»¥éç¨å表ååºã
ããè§åï¼é»è®¤ååºä¸ºDEFAULTï¼è¥ä¸æ·»å DEFAULTçååºæå
¥æ°å¼ä¸å±äºæ设置çååºä¼æ¥éã
ããä¾ä¸ãå§æ°
ããCREATE TABLE PART_TAB_CUSTOMER_BY_LIST
ãã(
ããCUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,
ããPHONE VARCHAR2(15) NOT NULL,
ããEMAIL VARCHAR2(80),
ããSEX VARCHAR2(10),
ããCORP_ID VARCHAR2(3),
ããINSERT_DATE DATEï¼
ããSUM_DATE varchar2(4)
ãã)
ããPARTITION BY LIST (SEX)
ãã(
ããPARTITION MALE VALUES ('ç·') TABLESPACE part_Data1,
ããPARTITION FEMALE VALUES ('女') TABLESPACE part_Data2
ãã)
ããä¾äºãvarchar2çæ¥æ
ããPARTITION BY LIST (SUM_DATE)
ãã(
ããPARTITION SUM_DATE1 VALUES ('2012') TABLESPACE part_Data1,
ããPARTITION SUM_DATE2 VALUES ('2013') TABLESPACE part_Data2ï¼
ããPARTITION SUM_DATE2 VALUES (DEFAULT) TABLESPACE part_Data2
ãã)
ãã3ãHASH æ£åååº
ãã说æï¼è¿ç±»ååºæ¯å¨åå¼ä¸ä½¿ç¨æ£åç®æ³ï¼ä»¥ç¡®å®å°è¡æ¾å
¥åªä¸ªååºä¸ã
ããè§åï¼å½åçå¼æ²¡æåéçæ¡ä»¶ï¼æ²¡æèå´çè§å¾ï¼ä¹æ²¡æåºå®çå¼ï¼å»ºè®®ä½¿ç¨æ£åååºã
ããæ£åååºä¸ºéè¿æå®ååºç¼å·æ¥åååå¸æ°æ®çä¸ç§ååºç±»åï¼å 为éè¿å¨I/O设å¤ä¸è¿è¡æ£åååºï¼
ãã使å¾è¿äºååºå¤§å°ä¸è´ã建议ååºçæ°ééç¨2çn次æ¹ï¼è¿æ ·å¯ä»¥ä½¿å¾å个ååºé´æ°æ®åå¸æ´å ååã
ããå建hashååºæ两ç§æ¹æ³ï¼ä¸ç§æ¹æ³æ¯æå®ååºçååï¼å¦ä¸ç§æ¹æ³æ¯æå®ååºæ°éã
ããä¾ä¸ã常è§æ¹æ³æå®ååºåå
ããCREATE TABLE PART_TAB_CUSTOMER_BY_HASH
ãã(
ããCUSTOMER_ID NUMBER NOT NULL PRIMARY KEY,
ããFIRST_NAME VARCHAR2(30) NOT NULL,
ããLAST_NAME VARCHAR2(30) NOT NULL,
ããPHONE VARCHAR2(15) NOT NULL,
ããEMAIL VARCHAR2(80),
ããSEX VARCHAR2(10),
ããSTATUS VARCHAR2(10),
ããINSERT_DATE DATE
ãã)
ããPARTITION BY HASH (CUSTOMER_ID) --æidæ£å
ãã(
ããPARTITION hash1 TABLESPACE part_Data1,
ããPARTITION hash2 TABLESPACE part_Data2
ãã)
ããä¾äºãæå®ååºæ°é
ããPARTITION BY HASH (empno) PARTITIONS 2 STORE IN (part_Data1,part_Data2);
ãã--å¾å¾æ们ä¸éè¦ç¥ébashååºçååï¼å 为æ°æ®æ¾å¨åªä¸ªååºæ¯Oracleæ ¹æ®bashç®æ³åæ¾çï¼å¹¶ä¸æ¯ç¨æ·æå®ï¼
ããæ以å½ç¨æ·æå
¥ä¸æ¡è®°å½ï¼å¹¶ä¸è½ç¡®å®æ¾å¨åªä¸ªååºï¼è¿ä¸ªä¸åäºrangeålist
ãã3ãå¤åååº
ãã说æï¼é¡¾åæä¹ï¼å¤åååºå°±ç±range+list+hash两两ç»åèæ¥ï¼ä¸è¬å为range+list,list+range,range+hash,list+bashï¼è¿éæååºå ç§å¸¸ç¨ç»åã
ããè§åï¼å¦æç»åä¸åå¨hashï¼çæhashååºä½ä¸ºåååºï¼åå 大家å¯ä»¥éè¿hashååºçæ§è´¨ç¥éã
ããä¾ä¸ãrange+listï¼è¿ç§ååºæ¯åºäºèå´ååºåå表ååºï¼è¡¨é¦å
ææåè¿è¡èå´ååºï¼ç¶ååææåè¿è¡å表ååºã
ããCREATE TABLE PART_TAB_SALE_RANGE_LIST
ãã(
ããPRODUCT_ID VARCHAR2(5),
ããSALES_DATE DATE,
ããSALES_COST NUMBER(10),
ããSTATUS VARCHAR2(10),
ãã)
ããPARTITION BY RANGE(SALES_DATE)
ããSUBPARTITION BY LIST (STATUS)
ãã(
ããPARTITION P1 VALUES LESS THAN (TO_DATE('2003-01-01','YYYY-MM-DD')) TABLESPACE part_Data1
ãã(
ããSUBPARTITION P1SUB1 VALUES ('ACTIVE') TABLESPACE part_Data1,
ããSUBPARTITION P1SUB2 VALUES ('INACTIVE') TABLESPACE part_Data2,
ããSUBPARTITION P1SUB3 VALUES (DEFAULT) TABLESPACE part_Data3
ãã),
ããPARTITION P2 VALUES LESS THAN (TO_DATE('2003-03-01','YYYY-MM-DD')) TABLESPACE part_Data2
ãã(
ããSUBPARTITION P2SUB1 VALUES ('ACTIVE') TABLESPACE part_Data1,
ããSUBPARTITION P2SUB2 VALUES ('INACTIVE') TABLESPACE part_Data2,
ããSUBPARTITION P2SUB3 VALUES (DEFAULT) TABLESPACE part_Data3
ãã),
ããPARTITION P3 VALUES LESS THAN (maxvalue) TABLESPACE part_Data3
ãã(
ããSUBPARTITION P3SUB1 VALUES ('ACTIVE') TABLESPACE part_Data1,
ããSUBPARTITION P3SUB2 VALUES ('INACTIVE') TABLESPACE part_Data2,
ããSUBPARTITION P3SUB3 VALUES (DEFAULT) TABLESPACE part_Data3
ãã)
ãã)
ããä¾äºãrange+bashï¼è¿ç§ååºæ¯åºäºèå´ååºåæ£åååºï¼è¡¨é¦å
ææåè¿è¡èå´ååºï¼ç¶ååææåè¿è¡æ£åååºã
ããpartition by range(transaction_date)
ããsubpartition by hash(transaction_id) subpartitions 3 store in (dinya_space01,dinya_space02,dinya_space03)
ãã(partition part_01 values less than(to_date(â2006-01-01â,âyyyy-mm-ddâ)),
ããpartition part_02 values less than(to_date(â2010-01-01â,âyyyy-mm-ddâ)),
ããpartition part_03 values less than(maxvalue)
ãã);
ããä¸ãååºè¡¨çæä½
ãã1.DMLæä½
ãã说æï¼DMLæä½å平常ç表ä¸æ ·ï¼æå¼äºçå°æ¹æ¯å¢å äºå¯ä»¥æå®è¡¨çç¹å®ååºææ§è¡DMLæä½ã
ããä¾å¦ï¼æ¥è¯¢ååºè¡¨
ããSELECT * FROM PART_TAB_SALE_RANGE_LIST;--ä¸æå®ååºç´æ¥æ¥è¯¢
ããSELECT * FROM PART_TAB_SALE_RANGE_LIST PARTITION(P2);--æå®ååºæ¥è¯¢
ããSELECT * FROM PART_TAB_SALE_RANGE_LIST SUBPARTITION(P1SUB2);--æå®å°ååºæ¥è¯¢
ãã对äºååºè¡¨ï¼æå®ååºæ§è¡DMLæçæ´é«ï¼ä½ï¼å¦ææå®äºååºï¼èæ¡ä»¶ä¸çæ°æ®åä¸å¨è¯¥ååºä¸æ¶ï¼å°ä¸ä¼äº§çä»»ä½DMLæä½ã
ãã2.DDLæä½
ãã1ï¼æ·»å ååº
ããï¼1ï¼å¯¹rangeååºè¡¨æ·»å ååº
ããALTER TABLE PART_TAB_SALE_RANGE_LIST ADD PARTITION P3 VALUES LESS THAN(TO_DATE('2009-06-01','YYYY-MM-DD'));
ãã注æï¼å¢å ä¸ä¸ªååºçæ¶åï¼å¢å çååºçæ¡ä»¶å¿
须大äºç°æååºçæ大å¼ï¼å¦åç³»ç»å°æ示ORA-14074 partition bound must collate higher than that of the last partition é误ã
ããï¼2ï¼å¯¹rangeååºè¡¨liståååºæ·»å ååº
ããALTER TABLE PART_TAB_SALE_RANGE_LIST MODIFY PARTITION P3 ADD SUBPARTITION P3SUB1 VALUES('COMPLETE');
ãã2ï¼å é¤ååº
ããï¼1ï¼å¯¹rangeååºè¡¨å é¤ååº
ããALTER TABLE PART_TAB_SALE_RANGE_LIST DROP PARTITION P3;
ããï¼2ï¼å¯¹rangeååºè¡¨liståååºå é¤åååº
ããALTER TABLE PART_TAB_SALE_RANGE_LIST DROP SUBPARTITION P4SUB1;
ãã注æï¼å¦æå é¤çååºæ¯è¡¨ä¸å¯ä¸çååºï¼é£ä¹æ¤ååºå°ä¸è½è¢«å é¤ï¼è¦æ³å é¤æ¤ååºï¼å¿
é¡»å é¤è¡¨ã
ãã3ï¼æªæååº
ãã说æï¼æªææ个ååºæ¯ææ¸
空æ个ååºä¸çæ°æ®ï¼å¹¶ä¸ä¼å é¤ååºï¼ä¹ä¸ä¼å é¤å
¶å®ååºä¸çæ°æ®ãå½è¡¨ä¸å³ä½¿åªæä¸ä¸ªååºæ¶ï¼ä¹å¯ä»¥æªæ该ååºã
ãã注æï¼å¦ææªæçååºè¡¨æ约æï¼éè¦å
å
³é约æãalter table sales disable/enable constraint restraint_nameï¼æªæååºä¼ä½¿å
¨å±ç´¢å¼æ æï¼éè¦é建ã
ãã(1)æ¸
空ååºï¼
ããALTER TABLE SALES TRUNCATE PARTITION P2;--è¿ç§æ¹å¼ä½¿å
¨å±ååºç´¢å¼æ æ
ããALTER TABLE SALES TRUNCATE PARTITION P2 update indexes;--è¿ç§æ¹å¼ä½¿å
¨å±ååºç´¢å¼ææUPDATE GLOBAL INDEXES
ãã(2)æ¸
空åååºï¼
ããALTER TABLE PART_TAB_SALE_RANGE_LIST TRUNCATE SUBPARTITION P2SUB2;
ããALTER TABLE PART_TAB_SALE_RANGE_LIST TRUNCATE SUBPARTITION P2SUB2 update indexes;
ãã4ï¼å并ååº
ãã说æï¼å并ååºæ¯å°ç¸é»çååºå并æä¸ä¸ªååºï¼ç»æååºå°éç¨è¾é«ååºççéï¼å¼å¾æ³¨æçæ¯ï¼ä¸è½å°ååºå并å°çéè¾ä½çååºã
ããALTER TABLE PART_TAB_SALE_RANGE_LIST MERGE PARTITIONS P1,P2 INTO PARTITION P2;
ãã注æï¼å¨æ¬ä¾ä¸å°åæç表çpart_01ååºåpart_02ååºè¿è¡äºå并ï¼å并åçååºä¸ºpart_02,
ããå¦æå¨å并çæ¶åæå并åçååºå®ä¸ºpart_01çæ¶åï¼ç³»ç»å°æ示ORA-14275 cannot reuse lower-bound partition as resulting partition é误ã
ãã5ï¼æåååº
ãã说æï¼æåååºå°ä¸ä¸ªååºæå两个æ°ååºï¼æåååæ¥ååºä¸ååå¨ã注æä¸è½å¯¹HASHç±»åçååºè¿è¡æåã
ããALTER TABLE PART_TAB_SALE_RANGE_LIST SBLIT PARTITION P2 AT(TO_DATE('2003-03-01','YYYY-MM-DD')) INTO (PARTITION P21,PARTITION P22);
ãã6ï¼æ¥åååº
ãã说æï¼æ¥åååºæ¯å°æ£åååºä¸çæ°æ®æ¥åå°å
¶å®ååºä¸ï¼å½æ£åååºä¸çæ°æ®æ¯è¾å¤§æ¶ï¼å¯ä»¥å¢å æ£åååºï¼ç¶åè¿è¡æ¥åï¼
ããå¼å¾æ³¨æçæ¯ï¼æ¥åååºåªè½ç¨äºæ£åååºä¸ã
ããALTER TABLE PART_TAB_SALE_RANGE_LIST COALESCA PARTITION;
ãã7ï¼éå½å表ååº
ããALTER TABLE SALES RENAME PARTITION P21 TO P2;
ãã8ï¼ç§»å¨ååº
ãã说æï¼æååºç§»å¨å°ä»¤ä¸ä¸ªè¡¨ç©ºé´ï¼ç§»å¨åè¦é建索å¼
ããalter table sales move partiton sp1 tablespace tablespace_name;
ããalter index index_name rebuild;
ãã--æ¥è¯¢æ¯å¦ç§»å¨æå SELECT TABLE_OWNER,TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME,SUBPARTITION_COUNT FROM DBA_TAB_PARTITIONS WHERE TABLE_OWNER='SCOTT';
ããåã表ååºç¸å
³çæ°æ®åå
¸è¡¨
ãã--æ¾ç¤ºè¡¨ååºä¿¡æ¯ æ¾ç¤ºæ°æ®åºææååºè¡¨ç详ç»ååºä¿¡æ¯ï¼ select * from DBA_TAB_PARTITIONS
ãã--æ¾ç¤ºåååºä¿¡æ¯ æ¾ç¤ºæ°æ®åºææç»åååºè¡¨çåååºä¿¡æ¯ï¼ select * from DBA_TAB_SUBPARTITIONS
ãã--æ¾ç¤ºæ°æ®åºææååºè¡¨çä¿¡æ¯ï¼ select * from DBA_PART_TABLES
ãã--æ¾ç¤ºæ°æ®åºå¯è®¿é®çææååºè¡¨çååºåä¿¡æ¯ï¼select * from DBA_PART_KEY_COLUMNS
ããDBA_IND_PARTITIONS
ããDBA_IND_SUBPARTITIONS
ãã--æ¥è¯¢ç´¢å¼ä¿¡æ¯
ããselect object_name,object_type,tablespace_name,sum(value)
ããfrom v$segment_statistics
ããwhere statistic_name IN ('physical reads','physical write','logical reads') and object_type='INDEX'
ããgroup by object_name,object_type,tablespace_name
ããorder by 4 desc
ããäºãå±é¨ç´¢å¼ä¸å
¨å±ç´¢å¼
ãã表å¯ä»¥ærangeï¼hashï¼listååºï¼è¡¨ååºåï¼å
¶ä¸çç´¢å¼åæ®é表ä¸çç´¢å¼ææä¸åï¼oracle对äºååºè¡¨ä¸çç´¢å¼å为2ç±»ï¼å³å±é¨ç´¢å¼åå
¨å±ç´¢å¼ã
ããå
³äºç±Oracleååºè¡¨å¼åºçå±é¨ç´¢å¼ä¸å
¨å±ç´¢å¼ï¼æ¥ç âOracle ç´¢å¼â
温馨提示:答案为网友推荐,仅供参考