ç´¢å¼æ¯æé«æ°æ®æ¥è¯¢æææçæ¹æ³ï¼ä¹æ¯æé¾å
¨é¢ææ¡çææ¯ï¼å 为æ£ç¡®çç´¢å¼å¯è½ä½¿æçæé«10000åï¼èæ æçç´¢å¼å¯è½æ¯æµªè´¹äºæ°æ®åºç©ºé´ï¼çè³å¤§å¤§éä½æ¥è¯¢æ§è½ã
ç´¢å¼ç管çææ¬
1ã åå¨ç´¢å¼çç£ç空é´
2ã æ§è¡æ°æ®ä¿®æ¹æä½ï¼INSERTãUPDATEãDELETEï¼äº§ççç´¢å¼ç»´æ¤
3ã å¨æ°æ®å¤çæ¶åéé¢å¤çåé空é´ã
å®é
æ°æ®ä¿®æ¹æµè¯ï¼
ä¸ä¸ªè¡¨æå段AãBãCï¼åæ¶è¿è¡æå
¥10000è¡è®°å½æµè¯
å¨æ²¡æ建索å¼æ¶å¹³åå®ææ¶é´æ¯2.9ç§
å¨å¯¹Aå段建索å¼åå¹³åå®ææ¶é´æ¯6.7ç§
å¨å¯¹Aå段åBå段建索å¼åå¹³åå®ææ¶é´æ¯10.3ç§
å¨å¯¹Aå段ãBå段åCå段é½å»ºç´¢å¼åå¹³åå®ææ¶é´æ¯11.7ç§
ä»ä»¥ä¸æµè¯ç»æå¯ä»¥ææ¾çåºç´¢å¼å¯¹æ°æ®ä¿®æ¹äº§ççå½±å
ç´¢å¼æåå¨æ¹æ³åç±»
B*æ ç´¢å¼
B*æ ç´¢å¼æ¯æ常ç¨çç´¢å¼ï¼å
¶åå¨ç»æ类似书çç´¢å¼ç»æï¼æåæ¯åå¶ä¸¤ç§ç±»åçåå¨æ°æ®åï¼åæ¯åç¸å½äºä¹¦ç大ç®å½ï¼å¶åç¸å½äºç´¢å¼å°çå
·ä½ç书页ãä¸è¬ç´¢å¼åå¯ä¸çº¦æç´¢å¼é½ä½¿ç¨B*æ ç´¢å¼ã
ä½å¾ç´¢å¼
ä½å¾ç´¢å¼å¨å主è¦ç¨æ¥èç空é´ï¼åå°ORACLE对æ°æ®åç访é®ï¼å®éç¨ä½å¾å移æ¹å¼æ¥ä¸è¡¨çè¡IDå·å¯¹åºï¼éç¨ä½å¾ç´¢å¼ä¸è¬æ¯éå¤å¼å¤ªå¤ç表å段ãä½å¾ç´¢å¼å¨å®é
å¯éåOLTPï¼æ°æ®äºå¡å¤çï¼ä¸ç¨å¾æ¯è¾å°ï¼å 为OLTPä¼å¯¹è¡¨è¿è¡å¤§éçå é¤ãä¿®æ¹ãæ°å»ºæä½ï¼ORACLEæ¯æ¬¡è¿è¡æä½é½ä¼å¯¹è¦æä½çæ°æ®åå éï¼æ以å¤äººæä½å¾å®¹æ产çæ°æ®åéçå¾
çè³æ»éç°è±¡ãå¨OLAPï¼æ°æ®åæå¤çï¼ä¸åºç¨ä½å¾æä¼å¿ï¼å 为OLAPä¸å¤§é¨åæ¯å¯¹æ°æ®åºçæ¥è¯¢æä½ï¼èä¸ä¸è¬éç¨æ°æ®ä»åºææ¯ï¼æ以大éæ°æ®éç¨ä½å¾ç´¢å¼èç空é´æ¯è¾ææ¾ã
ç´¢å¼æåè½åç±»
å¯ä¸ç´¢å¼
å¯ä¸ç´¢å¼æ两个ä½ç¨ï¼ä¸ä¸ªæ¯æ°æ®çº¦æï¼ä¸ä¸ªæ¯æ°æ®ç´¢å¼ï¼å
¶ä¸æ°æ®çº¦æ主è¦ç¨æ¥ä¿è¯æ°æ®çå®æ´æ§ï¼å¯ä¸ç´¢å¼äº§ççç´¢å¼è®°å½ä¸æ¯ä¸æ¡è®°å½é½å¯¹åºä¸ä¸ªå¯ä¸çROWIDã
主å
³é®åç´¢å¼
主å
³é®åç´¢å¼äº§ççç´¢å¼åå¯ä¸ç´¢å¼ï¼åªä¸è¿å®æ¯å¨æ°æ®åºå»ºç«ä¸»å
³é®åæ¶ç³»ç»èªå¨å»ºç«çã
ä¸è¬ç´¢å¼
ä¸è¬ç´¢å¼ä¸äº§çæ°æ®çº¦æä½ç¨ï¼å
¶åè½ä¸»è¦æ¯å¯¹å段建ç«ç´¢å¼è¡¨ï¼ä»¥æé«æ°æ®æ¥è¯¢é度ã
ç´¢å¼æç´¢å¼å¯¹è±¡åç±»
ååç´¢å¼ï¼è¡¨å个å段çç´¢å¼ï¼
å¤åç´¢å¼ï¼è¡¨å¤ä¸ªå段çç´¢å¼ï¼
å½æ°ç´¢å¼ï¼å¯¹å段è¿è¡å½æ°è¿ç®çç´¢å¼ï¼
建ç«å½æ°ç´¢å¼çæ¹æ³ï¼
create index æ¶è´¹æ¥æç´¢å¼ on GC_DFSS(trunc(sk_rq))
create index å®å
¨å®¢æ·ç¼å·ç´¢å¼ on yhzl(qc_bh||kh_bh)
å¨å¯¹å½æ°è¿è¡äºç´¢å¼åï¼å¦æå½åä¼è¯è¦å¼ç¨åºè®¾ç½®å½åä¼è¯çquery_rewrite_enabled为TRUEã
alter session set query_rewrite_enabled=true
注ï¼å¦æ对ç¨æ·å½æ°è¿è¡ç´¢å¼çè¯ï¼é£ç¨æ·å½æ°åºå ä¸ deterministicåæ°ï¼æææ¯å½æ°å¨è¾å
¥å¼åºå®çæ
åµä¸è¿åå¼ä¹åºå®ãä¾ï¼
create or replace function trunc_addï¼input_date dateï¼return date deterministic
as
begin
return trunc(input_date+1);
end trunc_add;
åºç¨ç´¢å¼çæ«æåç±»
INDEX UNIQUE SCANï¼æç´¢å¼å¯ä¸å¼æ«æï¼
select * from zl_yhjbqk where hbs_bh='5420016000'
INDEX RANGE SCANï¼æç´¢å¼å¼èå´æ«æï¼
select * from zl_yhjbqk where hbs_bh>'5420016000'
select * from zl_yhjbqk where qc_bh>'7001'
INDEX FAST FULL SCANï¼æç´¢å¼å¼å¿«éå
¨é¨æ«æï¼
select hbs_bh from zl_yhjbqk order by hbs_bh
select count(*) from zl_yhjbqk
select qc_bh from zl_yhjbqk group by qc_bh
ä»ä¹æ
åµä¸åºè¯¥å»ºç«ç´¢å¼
表ç主å
³é®å
èªå¨å»ºç«å¯ä¸ç´¢å¼
å¦zl_yhjbqkï¼ç¨æ·åºæ¬æ
åµï¼ä¸çhbs_bhï¼æ·æ è¯ç¼å·ï¼
表çå段å¯ä¸çº¦æ
ORACLEå©ç¨ç´¢å¼æ¥ä¿è¯æ°æ®çå®æ´æ§
å¦lc_hjï¼æµç¨ç¯èï¼ä¸çlc_bh+hj_sxï¼æµç¨ç¼å·+ç¯è顺åºï¼
ç´æ¥æ¡ä»¶æ¥è¯¢çå段
å¨SQLä¸ç¨äºæ¡ä»¶çº¦æçå段
å¦zl_yhjbqkï¼ç¨æ·åºæ¬æ
åµï¼ä¸çqc_bhï¼åºåç¼å·ï¼
select * from zl_yhjbqk where qc_bh=â7001â
æ¥è¯¢ä¸ä¸å
¶å®è¡¨å
³èçå段
å段常常建ç«äºå¤é®å
³ç³»
å¦zl_ydcfï¼ç¨çµæ份ï¼ä¸çjldb_bhï¼è®¡éç¹è¡¨ç¼å·ï¼
select * from zl_ydcf a,zl_yhdb b where a.jldb_bh=b.jldb_bh and b.jldb_bh=â540100214511â
æ¥è¯¢ä¸æåºçå段
æåºçå段å¦æéè¿ç´¢å¼å»è®¿é®é£å°å¤§å¤§æé«æåºé度
select * from zl_yhjbqk order by qc_bhï¼å»ºç«qc_bhç´¢å¼ï¼
select * from zl_yhjbqk where qc_bh='7001' order by cb_sxï¼å»ºç«qc_bh+cb_sxç´¢å¼ï¼æ³¨ï¼åªæ¯ä¸ä¸ªç´¢å¼ï¼å
¶ä¸å
æ¬qc_bhåcb_sxå段ï¼
æ¥è¯¢ä¸ç»è®¡æåç»ç»è®¡çå段
select max(hbs_bh) from zl_yhjbqk
select qc_bh,count(*) from zl_yhjbqk group by qc_bh
ä»ä¹æ
åµä¸åºä¸å»ºæå°å»ºç´¢å¼
表记å½å¤ªå°
å¦æä¸ä¸ªè¡¨åªæ5æ¡è®°å½ï¼éç¨ç´¢å¼å»è®¿é®è®°å½çè¯ï¼é£é¦å
é访é®ç´¢å¼è¡¨ï¼åéè¿ç´¢å¼è¡¨è®¿é®æ°æ®è¡¨ï¼ä¸è¬ç´¢å¼è¡¨ä¸æ°æ®è¡¨ä¸å¨åä¸ä¸ªæ°æ®åï¼è¿ç§æ
åµä¸ORACLEè³å°è¦å¾è¿è¯»åæ°æ®å两次ãèä¸ç¨ç´¢å¼çæ
åµä¸ORACLEä¼å°ææçæ°æ®ä¸æ¬¡è¯»åºï¼å¤çé度æ¾ç¶ä¼æ¯ç¨ç´¢å¼å¿«ã
å¦è¡¨zl_sybmï¼ä½¿ç¨é¨é¨ï¼ä¸è¬åªæå æ¡è®°å½ï¼é¤äºä¸»å
³é®åå¤å¯¹ä»»ä½ä¸ä¸ªå段建索å¼é½ä¸ä¼äº§çæ§è½ä¼åï¼å®é
ä¸å¦æ对è¿ä¸ªè¡¨è¿è¡äºç»è®¡åæåORACLEä¹ä¸ä¼ç¨ä½ 建çç´¢å¼ï¼èæ¯èªå¨æ§è¡å
¨è¡¨è®¿é®ãå¦ï¼
select * from zl_sybm where sydw_bh='5401'ï¼å¯¹sydw_bh建ç«ç´¢å¼ä¸ä¼äº§çæ§è½ä¼åï¼
ç»å¸¸æå
¥ãå é¤ãä¿®æ¹ç表
对ä¸äºç»å¸¸å¤ççä¸å¡è¡¨åºå¨æ¥è¯¢å
许çæ
åµä¸å°½éåå°ç´¢å¼ï¼å¦zl_yhbmï¼gc_dfssï¼gc_dfysï¼gc_fpdyçä¸å¡è¡¨ã
æ°æ®éå¤ä¸åå¸å¹³åç表å段
åå¦ä¸ä¸ªè¡¨æ10ä¸è¡è®°å½ï¼æä¸ä¸ªå段AåªæTåF两ç§å¼ï¼ä¸æ¯ä¸ªå¼çåå¸æ¦ç大约为50%ï¼é£ä¹å¯¹è¿ç§è¡¨Aå段建索å¼ä¸è¬ä¸ä¼æé«æ°æ®åºçæ¥è¯¢é度ã
ç»å¸¸å主å段ä¸åæ¥è¯¢ä½ä¸»å段索å¼å¼æ¯è¾å¤ç表å段
å¦gc_dfssï¼çµè´¹å®æ¶ï¼è¡¨ç»å¸¸ææ¶è´¹åºå·ãæ·æ è¯ç¼å·ãæ表æ¥æãçµè´¹åçå¹´æãæä½æ å¿æ¥å
·ä½æ¥è¯¢æä¸ç¬æ¶æ¬¾çæ
åµï¼å¦æå°ææçå段é½å»ºå¨ä¸ä¸ªç´¢å¼éé£å°ä¼å¢å æ°æ®çä¿®æ¹ãæå
¥ãå é¤æ¶é´ï¼ä»å®é
ä¸åæä¸ç¬æ¶æ¬¾å¦æææ¶è´¹åºå·ç´¢å¼å°±å·²ç»å°è®°å½åå°å°åªæå æ¡ï¼å¦æåæåé¢çå 个å段索å¼æ¥è¯¢å°å¯¹æ§è½ä¸äº§ç太大çå½±åã
å¦ä½åªéè¿ç´¢å¼è¿åç»æ
ä¸ä¸ªç´¢å¼ä¸è¬å
æ¬å个æå¤ä¸ªå段ï¼å¦æè½ä¸è®¿é®è¡¨ç´æ¥åºç¨ç´¢å¼å°±è¿åç»æé£å°å¤§å¤§æé«æ°æ®åºæ¥è¯¢çæ§è½ã对æ¯ä»¥ä¸ä¸ä¸ªSQLï¼å
¶ä¸å¯¹è¡¨zl_yhjbqkçhbs_bhåqc_bhå段建ç«äºç´¢å¼ï¼
1 select hbs_bh,qc_bh,xh_bz from zl_yhjbqk where qc_bh=â7001â
æ§è¡è·¯å¾:
SELECT STATEMENT, GOAL = CHOOSE 11 265 5565
TABLE ACCESS BY INDEX ROWID DLYX ZL_YHJBQK 11 265 5565
INDEX RANGE SCAN DLYX åºåç´¢å¼ 1 265
å¹³åæ§è¡æ¶é´ï¼0.078ç§ï¼
2 select hbs_bh,qc_bh from zl_yhjbqk where qc_bh=â7001â
æ§è¡è·¯å¾:
SELECT STATEMENT, GOAL = CHOOSE 11 265 3710
TABLE ACCESS BY INDEX ROWID DLYX ZL_YHJBQK 11 265 3710
INDEX RANGE SCAN DLYX åºåç´¢å¼ 1 265
å¹³åæ§è¡æ¶é´ï¼0.078ç§ï¼
3 select qc_bh from zl_yhjbqk where qc_bh=â7001â
æ§è¡è·¯å¾:
SELECT STATEMENT, GOAL = CHOOSE 1 265 1060
INDEX RANGE SCAN DLYX åºåç´¢å¼ 1 265 1060
å¹³åæ§è¡æ¶é´ï¼0.062ç§ï¼
ä»æ§è¡ç»æå¯ä»¥çåºç¬¬ä¸æ¡SQLçæçæé«ãæ§è¡è·¯å¾å¯ä»¥çåºç¬¬1ã2æ¡SQLé½å¤æ§è¡äºTABLE ACCESS BY INDEX ROWIDï¼éè¿ROWID访é®è¡¨ï¼ è¿ä¸ªæ¥éª¤ï¼å 为è¿åçç»æåä¸å
æ¬å½å使ç¨ç´¢å¼(qc_bh)ä¸æªç´¢å¼çåï¼hbs_bh,xh_bzï¼ï¼è第3æ¡SQLç´æ¥éè¿QC_BHè¿åäºç»æï¼è¿å°±æ¯éè¿ç´¢å¼ç´æ¥è¿åç»æçæ¹æ³ã
å¦ä½é建索å¼
alter index 表çµéç»æè¡¨ä¸»é® rebuild
å¦ä½å¿«éæ°å»ºå¤§æ°æ®é表çç´¢å¼
å¦æä¸ä¸ªè¡¨çè®°å½è¾¾å°100ä¸ä»¥ä¸çè¯ï¼è¦å¯¹å
¶ä¸ä¸ä¸ªå段建索å¼å¯è½è¦è±å¾é¿çæ¶é´ï¼çè³å¯¼è´æå¡å¨æ°æ®åºæ»æºï¼å 为å¨å»ºç´¢å¼çæ¶åORACLEè¦å°ç´¢å¼å段ææçå
容ååºå¹¶è¿è¡å
¨é¢æåºï¼æ°æ®é大çè¯å¯è½å¯¼è´æå¡å¨æåºå
åä¸è¶³èå¼ç¨ç£ç交æ¢ç©ºé´è¿è¡ï¼è¿å°ä¸¥éå½±åæå¡å¨æ°æ®åºçå·¥ä½ã解å³æ¹æ³æ¯å¢å¤§æ°æ®åºå¯å¨åå§åä¸çæåºå
ååæ°ï¼å¦æè¦è¿è¡å¤§éçç´¢å¼ä¿®æ¹å¯ä»¥è®¾ç½®10M以ä¸çæåºå
åï¼ORACLE缺ç大å°ä¸º64Kï¼ï¼å¨ç´¢å¼å»ºç«å®æååºå°åæ°ä¿®æ¹åæ¥ï¼å 为å¨å®é
OLTPæ°æ®åºåºç¨ä¸ä¸è¬ä¸ä¼ç¨å°è¿ä¹å¤§çæåºå
åã
温馨提示:内容为网友见解,仅供参考