ä¸é¢ä»¥å
³ç³»æ°æ®åºç³»ç»Informix为ä¾ï¼ä»ç»æ¹åç¨æ·æ¥è¯¢è®¡åçæ¹æ³ã
1ï¼åç使ç¨ç´¢å¼
ç´¢å¼æ¯æ°æ®åºä¸éè¦çæ°æ®ç»æï¼å®çæ ¹æ¬ç®çå°±æ¯ä¸ºäºæé«æ¥è¯¢æçãç°å¨å¤§å¤æ°çæ°æ®åºäº§åé½éç¨IBMæå
æåºçISAMç´¢å¼ç»æãç´¢å¼ç使ç¨è¦æ°å°å¥½å¤ï¼å
¶ä½¿ç¨ååå¦ä¸ï¼
âå¨ç»å¸¸è¿è¡è¿æ¥ï¼ä½æ¯æ²¡ææå®ä¸ºå¤é®çåä¸å»ºç«ç´¢å¼ï¼èä¸ç»å¸¸è¿æ¥çå段åç±ä¼åå¨èªå¨çæç´¢å¼ã
âå¨é¢ç¹è¿è¡æåºæåç»ï¼å³è¿è¡group byæorder byæä½ï¼çåä¸å»ºç«ç´¢å¼ã
âå¨æ¡ä»¶è¡¨è¾¾å¼ä¸ç»å¸¸ç¨å°çä¸åå¼è¾å¤çåä¸å»ºç«æ£ç´¢ï¼å¨ä¸åå¼å°çåä¸ä¸è¦å»ºç«ç´¢å¼ãæ¯å¦å¨éå表çâæ§å«âåä¸åªæâç·âä¸â女â两个ä¸åå¼ï¼å æ¤å°±æ å¿
è¦å»ºç«ç´¢å¼ãå¦æ建ç«ç´¢å¼ä¸ä½ä¸ä¼æé«æ¥è¯¢æçï¼åèä¼ä¸¥ééä½æ´æ°é度ã
âå¦æå¾
æåºçåæå¤ä¸ªï¼å¯ä»¥å¨è¿äºåä¸å»ºç«å¤åç´¢å¼ï¼compound indexï¼ã
â使ç¨ç³»ç»å·¥å
·ãå¦Informixæ°æ®åºæä¸ä¸ªtbcheckå·¥å
·ï¼å¯ä»¥å¨å¯ççç´¢å¼ä¸è¿è¡æ£æ¥ãå¨ä¸äºæ°æ®åºæå¡å¨ä¸ï¼ç´¢å¼å¯è½å¤±ææè
å 为é¢ç¹æä½è使å¾è¯»åæçéä½ï¼å¦æä¸ä¸ªä½¿ç¨ç´¢å¼çæ¥è¯¢ä¸æä¸ç½å°æ
¢ä¸æ¥ï¼å¯ä»¥è¯çç¨tbcheckå·¥å
·æ£æ¥ç´¢å¼çå®æ´æ§ï¼å¿
è¦æ¶è¿è¡ä¿®å¤ãå¦å¤ï¼å½æ°æ®åºè¡¨æ´æ°å¤§éæ°æ®åï¼å é¤å¹¶é建索å¼å¯ä»¥æé«æ¥è¯¢é度ã
2ï¼é¿å
æç®åæåº
åºå½ç®åæé¿å
对大å表è¿è¡éå¤çæåºãå½è½å¤å©ç¨ç´¢å¼èªå¨ä»¥éå½ç次åºäº§çè¾åºæ¶ï¼ä¼åå¨å°±é¿å
äºæåºçæ¥éª¤ã以ä¸æ¯ä¸äºå½±åå ç´ ï¼
âç´¢å¼ä¸ä¸å
æ¬ä¸ä¸ªæå 个å¾
æåºçåï¼
âgroup byæorder byåå¥ä¸åç次åºä¸ç´¢å¼ç次åºä¸ä¸æ ·ï¼
âæåºçåæ¥èªä¸åç表ã
为äºé¿å
ä¸å¿
è¦çæåºï¼å°±è¦æ£ç¡®å°å¢å»ºç´¢å¼ï¼åçå°å并æ°æ®åºè¡¨ï¼å°½ç®¡ææ¶å¯è½å½±å表çè§èåï¼ä½ç¸å¯¹äºæççæé«æ¯å¼å¾çï¼ãå¦ææåºä¸å¯é¿å
ï¼é£ä¹åºå½è¯å¾ç®åå®ï¼å¦ç¼©å°æåºçåçèå´çã
3ï¼æ¶é¤å¯¹å¤§å表è¡æ°æ®ç顺åºåå
å¨åµå¥æ¥è¯¢ä¸ï¼å¯¹è¡¨ç顺åºåå对æ¥è¯¢æçå¯è½äº§çè´å½çå½±åãæ¯å¦éç¨é¡ºåºååçç¥ï¼ä¸ä¸ªåµå¥3å±çæ¥è¯¢ï¼å¦ææ¯å±é½æ¥è¯¢1000è¡ï¼é£ä¹è¿ä¸ªæ¥è¯¢å°±è¦æ¥è¯¢10亿è¡æ°æ®ãé¿å
è¿ç§æ
åµç主è¦æ¹æ³å°±æ¯å¯¹è¿æ¥çåè¿è¡ç´¢å¼ãä¾å¦ï¼ä¸¤ä¸ªè¡¨ï¼å¦ç表ï¼å¦å·ãå§åãå¹´é¾â¦â¦ï¼åé课表ï¼å¦å·ã课ç¨å·ãæ绩ï¼ãå¦æ两个表è¦åè¿æ¥ï¼å°±è¦å¨âå¦å·âè¿ä¸ªè¿æ¥å段ä¸å»ºç«ç´¢å¼ã
è¿å¯ä»¥ä½¿ç¨å¹¶éæ¥é¿å
顺åºååã尽管å¨ææçæ£æ¥åä¸é½æç´¢å¼ï¼ä½æäºå½¢å¼çwhereåå¥å¼ºè¿«ä¼åå¨ä½¿ç¨é¡ºåºååãä¸é¢çæ¥è¯¢å°å¼ºè¿«å¯¹orders表æ§è¡é¡ºåºæä½ï¼
SELECT ï¼ FROM orders WHERE (customer_num=104 AND order_num>1001) OR order_num=1008
è½ç¶å¨customer_numåorder_numä¸å»ºæç´¢å¼ï¼ä½æ¯å¨ä¸é¢çè¯å¥ä¸ä¼åå¨è¿æ¯ä½¿ç¨é¡ºåºååè·¯å¾æ«ææ´ä¸ªè¡¨ãå 为è¿ä¸ªè¯å¥è¦æ£ç´¢çæ¯å离çè¡çéåï¼æ以åºè¯¥æ¹ä¸ºå¦ä¸è¯å¥ï¼
SELECT ï¼ FROM orders WHERE customer_num=104 AND order_num>1001
UNION
SELECT ï¼ FROM orders WHERE order_num=1008
è¿æ ·å°±è½å©ç¨ç´¢å¼è·¯å¾å¤çæ¥è¯¢ã
4ï¼é¿å
ç¸å
³åæ¥è¯¢
ä¸ä¸ªåçæ ç¾åæ¶å¨ä¸»æ¥è¯¢åwhereåå¥ä¸çæ¥è¯¢ä¸åºç°ï¼é£ä¹å¾å¯è½å½ä¸»æ¥è¯¢ä¸çåå¼æ¹åä¹åï¼åæ¥è¯¢å¿
é¡»éæ°æ¥è¯¢ä¸æ¬¡ãæ¥è¯¢åµå¥å±æ¬¡è¶å¤ï¼æçè¶ä½ï¼å æ¤åºå½å°½éé¿å
åæ¥è¯¢ãå¦æåæ¥è¯¢ä¸å¯é¿å
ï¼é£ä¹è¦å¨åæ¥è¯¢ä¸è¿æ»¤æå°½å¯è½å¤çè¡ã
5ï¼é¿å
å°é¾çæ£è§è¡¨è¾¾å¼
MATCHESåLIKEå
³é®åæ¯æéé
符å¹é
ï¼ææ¯ä¸å«æ£è§è¡¨è¾¾å¼ãä½è¿ç§å¹é
ç¹å«èè´¹æ¶é´ãä¾å¦ï¼SELECT ï¼ FROM customer WHERE zipcode LIKE â98_ _ _â
å³ä½¿å¨zipcodeå段ä¸å»ºç«äºç´¢å¼ï¼å¨è¿ç§æ
åµä¸ä¹è¿æ¯éç¨é¡ºåºæ«æçæ¹å¼ãå¦ææè¯å¥æ¹ä¸ºSELECT ï¼ FROM customer WHERE zipcode >â98000âï¼å¨æ§è¡æ¥è¯¢æ¶å°±ä¼å©ç¨ç´¢å¼æ¥æ¥è¯¢ï¼æ¾ç¶ä¼å¤§å¤§æé«é度ã
å¦å¤ï¼è¿è¦é¿å
éå¼å§çå串ãä¾å¦è¯å¥ï¼SELECT ï¼ FROM customer WHERE zipcode[2ï¼3]>â80âï¼å¨whereåå¥ä¸éç¨äºéå¼å§å串ï¼å èè¿ä¸ªè¯å¥ä¹ä¸ä¼ä½¿ç¨ç´¢å¼ã
6ï¼ä½¿ç¨ä¸´æ¶è¡¨å éæ¥è¯¢
æ表çä¸ä¸ªåéè¿è¡æåºå¹¶å建临æ¶è¡¨ï¼ææ¶è½å éæ¥è¯¢ãå®æå©äºé¿å
å¤éæåºæä½ï¼èä¸å¨å
¶ä»æ¹é¢è¿è½ç®åä¼åå¨çå·¥ä½ãä¾å¦ï¼
SELECT cust.nameï¼rcvbles.balanceï¼â¦â¦other columns
FROM custï¼rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
AND cust.postcode>â98000â
ORDER BY cust.name
å¦æè¿ä¸ªæ¥è¯¢è¦è¢«æ§è¡å¤æ¬¡èä¸æ¢ä¸æ¬¡ï¼å¯ä»¥ææææªä»æ¬¾ç客æ·æ¾åºæ¥æ¾å¨ä¸ä¸ªä¸´æ¶æ件ä¸ï¼å¹¶æ客æ·çååè¿è¡æåºï¼
SELECT cust.nameï¼rcvbles.balanceï¼â¦â¦other columns
FROM custï¼rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
ORDER BY cust.name
INTO TEMP cust_with_balance
ç¶å以ä¸é¢çæ¹å¼å¨ä¸´æ¶è¡¨ä¸æ¥è¯¢ï¼
SELECT ï¼ FROM cust_with_balance
WHERE postcode>â98000â
临æ¶è¡¨ä¸çè¡è¦æ¯ä¸»è¡¨ä¸çè¡å°ï¼èä¸ç©ç顺åºå°±æ¯æè¦æ±ç顺åºï¼åå°äºç£çI/Oï¼æ以æ¥è¯¢å·¥ä½éå¯ä»¥å¾å°å¤§å¹
åå°ã
注æï¼ä¸´æ¶è¡¨å建åä¸ä¼åæ 主表çä¿®æ¹ãå¨ä¸»è¡¨ä¸æ°æ®é¢ç¹ä¿®æ¹çæ
åµä¸ï¼æ³¨æä¸è¦ä¸¢å¤±æ°æ®ã
7ï¼ç¨æåºæ¥å代é顺åºåå
é顺åºç£çååæ¯ææ
¢çæä½ï¼è¡¨ç°å¨ç£çååèçæ¥å移å¨ãSQLè¯å¥éèäºè¿ä¸æ
åµï¼ä½¿å¾æ们å¨ååºç¨ç¨åºæ¶å¾å®¹æååºè¦æ±åå大éé顺åºé¡µçæ¥è¯¢ã
æäºæ¶åï¼ç¨æ°æ®åºçæåºè½åæ¥æ¿ä»£é顺åºçååè½æ¹è¿æ¥è¯¢ã
å®ä¾åæ
ä¸é¢æ们举ä¸ä¸ªå¶é å
¬å¸çä¾åæ¥è¯´æå¦ä½è¿è¡æ¥è¯¢ä¼åãå¶é å
¬å¸æ°æ®åºä¸å
æ¬3个表ï¼æ¨¡å¼å¦ä¸æ示ï¼
1ï¼part表
é¶ä»¶å·?????é¶ä»¶æè¿°????????å
¶ä»å
ï¼part_numï¼?ï¼part_descï¼??????ï¼other columnï¼
102ï¼032???Seageat 30G disk?????â¦â¦
500ï¼049???Novel 10M network card??â¦â¦
â¦â¦
2ï¼vendor表
ååå·??????ååå??????å
¶ä»å
ï¼vendor _numï¼?ï¼vendor_nameï¼ ï¼other columnï¼
910ï¼257?????Seageat Corp???â¦â¦
523ï¼045?????IBM Corp?????â¦â¦
â¦â¦
3ï¼parven表
é¶ä»¶å·?????ååå·?????é¶ä»¶æ°é
ï¼part_numï¼?ï¼vendor_numï¼?ï¼part_amountï¼
102ï¼032????910ï¼257????3,450,000
234ï¼423????321ï¼001????4ï¼000ï¼000
â¦â¦
ä¸é¢çæ¥è¯¢å°å¨è¿äºè¡¨ä¸å®æè¿è¡ï¼å¹¶äº§çå
³äºææé¶ä»¶æ°éçæ¥è¡¨ï¼
SELECT part_descï¼vendor_nameï¼part_amount
FROM partï¼vendorï¼parven
WHERE part.part_num=parven.part_num
AND parven.vendor_num = vendor.vendor_num
ORDER BY part.part_num
å¦æä¸å»ºç«ç´¢å¼ï¼ä¸è¿°æ¥è¯¢ä»£ç çå¼éå°åå巨大ã为æ¤ï¼æ们å¨é¶ä»¶å·åååå·ä¸å»ºç«ç´¢å¼ãç´¢å¼ç建ç«é¿å
äºå¨åµå¥ä¸åå¤æ«æãå
³äºè¡¨ä¸ç´¢å¼çç»è®¡ä¿¡æ¯å¦ä¸ï¼
表?????è¡å°ºå¯¸???è¡æ°é?????æ¯é¡µè¡æ°é???æ°æ®é¡µæ°é
ï¼tableï¼?(row size)?ï¼Row countï¼?ï¼Rows/Pagesï¼?ï¼Data Pagesï¼
part????150?????10ï¼000????25???????400
Vendor???150?????1ï¼000???? 25???????40
Parven???13????? 15ï¼000????300?????? 50
ç´¢å¼?????é®å°ºå¯¸???æ¯é¡µé®æ°é???页é¢æ°é
ï¼Indexesï¼?(Key Size)?ï¼Keys/Page)???(Leaf Pagesï¼
part?????4??????500???????20
Vendor????4??????500???????2
Parven????8??????250???????60
çèµ·æ¥æ¯ä¸ªç¸å¯¹ç®åç3表è¿æ¥ï¼ä½æ¯å
¶æ¥è¯¢å¼éæ¯å¾å¤§çãéè¿æ¥çç³»ç»è¡¨å¯ä»¥çå°ï¼å¨part_numä¸åvendor_numä¸æç°ç´¢å¼ï¼å æ¤ç´¢å¼æ¯æç
§ç©ç顺åºåæ¾çãparven表没æç¹å®çåæ¾æ¬¡åºãè¿äºè¡¨ç大å°è¯´æä»ç¼å²é¡µä¸é顺åºååçæåçå¾å°ãæ¤è¯å¥çä¼åæ¥è¯¢è§åæ¯ï¼é¦å
ä»partä¸é¡ºåºè¯»å400页ï¼ç¶åå对parven表é顺åºåå1ä¸æ¬¡ï¼æ¯æ¬¡2页ï¼ä¸ä¸ªç´¢å¼é¡µãä¸ä¸ªæ°æ®é¡µï¼ï¼æ»è®¡2ä¸ä¸ªç£ç页ï¼æå对vendor表é顺åºåå1.5ä¸æ¬¡ï¼å3ä¸ä¸ªç£ç页ãå¯ä»¥çåºå¨è¿ä¸ªç´¢å¼å¥½çè¿æ¥ä¸è±è´¹çç£çåå为5.04ä¸æ¬¡ã
温馨提示:内容为网友见解,仅供参考