EXPLAINã¯äœãæäŸããŸããïŒ
EXPLAINã¹ããŒãã¡ã³ãã®äœ¿çšã¯ç°¡åã§ãã SELECTã¹ããŒãã¡ã³ãã®åã«ã¯ãšãªã«è¿œå ããå¿ èŠããããŸãã åºåãåæããŠãããŒã ããè¿ãããæ å ±ãææ¡ããŸãããã
EXPLAIN SELECT * FROM categories
********************** 1. row ********************** id: 1 select_type: SIMPLE table: categories type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4 Extra: 1 row in set (0.00 sec)
åºåã¯ãŸã£ããåãããã«èŠããªãå ŽåããããŸãããåã10åãå«ãŸããŸãã ãããã®è¿ãããåã¯äœã§ããïŒ
- id-ã¯ãšãªå ã®åSELECTã®ã·ãªã¢ã«çªå·ïŒè€æ°ã®ãµãã¯ãšãªãããå ŽåïŒ
- select_typeã¯ãSELECTèŠæ±ã®ã¿ã€ãã§ãã
- SIMPLE-ãµãã¯ãšãªãŸãã¯UNIONã®ãªãåçŽãªSELECTã¯ãšãª
- PRIMARY-ãã®SELECTã¯JOINã®æãå€éšã®ã¯ãšãªã§ã
- 掟ç -ãã®SELECTã¯FROMå ã®ãµãã¯ãšãªã®äžéšã§ã
- SUBQUERY-ãµãã¯ãšãªã®æåã®SELECT
- åŸå±ãµãã¯ãšãª-å€éšã¯ãšãªã«äŸåãããµãã¯ãšãª
- ãã£ãã·ã¥ã§ããªããµãã¯ãšãª-ãã£ãã·ã¥ãããŠããªããµãã¯ãšãªïŒã¯ãšãªããã£ãã·ã¥ããã«ã¯ç¹å®ã®æ¡ä»¶ããããŸãïŒ
- UNION - UNIONã® 2çªç®ä»¥éã®SELECT
- DEPENDENT UNION-å€éšã¯ãšãªã«äŸåãããUNIONã®2çªç®ä»¥éã®SELECT
- UNION RESULT - UNIONã®çµæ
- ããŒãã« -衚瀺ãããè¡ãå±ããããŒãã«ã
- ã¿ã€ã -MySQLãªã³ã¯ãã©ã®ããã«ããŒãã«ã䜿çšãããã瀺ããŸãã ããã¯ãæ¬ èœããã€ã³ããã¯ã¹ããŸãã¯æžã蟌ãŸãããªã¯ãšã¹ãã確èªããŠæžãæããå¿
èŠãããçç±ãå ±åã§ãããããåºåã§æãæçšãªãã£ãŒã«ãã®1ã€ã§ãã
å¯èœãªå€ïŒ
- ã·ã¹ãã -ããŒãã«ã«ã¯1è¡ãããããŸãã
- Const-ããŒãã«ã«ã¯å¯Ÿå¿ããè¡ã1ã€ã ããããããã«ã¯ã€ã³ããã¯ã¹ãä»ããããŸãã ããã¯ãããŒãã«ãäžåºŠã ãèªã¿åãããæååã®å€ãå°æ¥ã®çµåã§å®æ°ãšããŠèªèããããããæéã®çµåã¿ã€ãã§ãã
- Eq_ref-ã€ã³ããã¯ã¹ã®ãã¹ãŠã®éšåããã€ã³ãã£ã³ã°ã«äœ¿çšãããŸãã 䜿çšãããã€ã³ããã¯ã¹ïŒPRIMARY KEYãŸãã¯UNIQUE NOT NULLã ããã¯ããã€ã³ãã£ã³ã°ã®ãã1ã€ã®æè¯ã®ã¿ã€ãã§ãã
- åç § -ã€ã³ããã¯ã¹åã®å¯Ÿå¿ãããã¹ãŠã®è¡ã¯ãåã®è¡šã®è¡ã®çµã¿åããããšã«èªã¿åãããŸãã ã€ã³ããã¯ã¹ä»ãåã®ãã®çµåã¿ã€ãã¯ã=ãŸãã¯<=>æŒç®åã䜿çšããããã«èŠããŸã
- ãã«ããã¹ã -æ¥ç¶ã¯ããŒãã«ã®ãã«ããã¹ãã€ã³ããã¯ã¹ã䜿çšããŸã
- Ref_or_nullã¯refãšåãã§ãããåã«nullå€ãæã€è¡ãå«ãŸããŸã
- Index_merge-æ¥ç¶ã¯ãã€ã³ããã¯ã¹ã®ãªã¹ãã䜿çšããŠçµæã»ãããååŸããŸãã EXPLAINã³ãã³ãåºåã®ããŒåã«ã¯ã䜿çšãããã€ã³ããã¯ã¹ã®ãªã¹ããå«ãŸããŸãã
- Unique_subquery -INãµãã¯ãšãªã¯ããŒãã«ãã1ã€ã®çµæã®ã¿ãè¿ããäž»ããŒã䜿çšããŸãã
- Index_subqueryã¯åã®ãã®ãšåãã§ãããè€æ°ã®çµæãè¿ããŸãã
- ç¯å² -éåžžãããŒåãBETWEENãINã>ã> =ãªã©ã®æŒç®åã䜿çšããŠå®æ°ãšæ¯èŒãããå Žåãç¹å®ã®ç¯å²å ã®å¯Ÿå¿ããè¡ãèŠã€ããããã«äœ¿çšãããã€ã³ããã¯ã¹
- ã€ã³ããã¯ã¹ -ã€ã³ããã¯ã¹ããªãŒå šäœãã¹ãã£ã³ããŠã察å¿ããè¡ãèŠã€ããŸãã
- ãã¹ãŠ -ããŒãã«å šäœãã¹ãã£ã³ããŠã察å¿ããè¡ãèŠã€ããŸãã ããã¯ææªã®ã¿ã€ãã®è€åã§ãããéåžžãããŒãã«ã«é©åãªã€ã³ããã¯ã¹ããªãããšã瀺ããŸãã
- possible_keys-ããŒãã«å ã®è¡ãèŠã€ããããã«äœ¿çšã§ããã€ã³ããã¯ã¹ã瀺ããŸãã å®éã«ã¯ã䜿çšãããå Žåãšäœ¿çšãããªãå ŽåããããŸãã å®éãNULLå€ã¯é©åãªã€ã³ããã¯ã¹ãèŠã€ãããªãã£ãããšã瀺ãããããã®åã¯ã¯ãšãªã®æé©åã«åœ¹ç«ã¡ãŸãã
- ã㌠-䜿çšãããŠããã€ã³ããã¯ã¹ã瀺ããŸãã ãã®åã«ã¯ãpossible_keysåã§æå®ãããŠããªãã€ã³ããã¯ã¹ãå«ãŸããå ŽåããããŸãã ããŒãã«ãçµåããããã»ã¹ã§ããªããã£ãã€ã¶ãŒã¯æé©ãªãªãã·ã§ã³ãæ¢ããpossible_keysã«ã¯è¡šç€ºãããªããã䜿çšã«æé©ãªããŒãèŠã€ããããšãã§ããŸãã
- Key_lenã¯ãMySQLãªããã£ãã€ã¶ãŒã䜿çšããããã«éžæããã€ã³ããã¯ã¹ã®é·ãã§ãã ããšãã°ãkey_lenã®å€ã4ã®å Žåã4æåãä¿åããã«ã¯ã¡ã¢ãªãå¿ èŠã§ãã ãã®ãããã¯ãžã®ãªã³ã¯ã¯ãã¡ã
- Ref-ããŒãã£ãŒã«ãã§æå®ãããã€ã³ããã¯ã¹ãšæ¯èŒãããåãŸãã¯å®æ°ã瀺ããŸãã MySQLã¯ãã¯ãšãªå®è¡ãã©ã³ã«åºã¥ããŠãæ¯èŒçšã®å®æ°å€ãŸãã¯ãã£ãŒã«ãèªäœãéžæããŸãã
- è¡ -åºåãååŸããããã«åŠçãããã¬ã³ãŒãã®æ°ã衚瀺ããŸãã ããã¯ãã¯ãšãªãç¹ã«JOINãšãµãã¯ãšãªã䜿çšããã¯ãšãªãæé©åããæ©äŒãæäŸãããã1ã€ã®éåžžã«éèŠãªãã£ãŒã«ãã§ãã
- Extra-ã¯ãšãªå®è¡ãã©ã³ã«é¢é£ããè¿œå æ å ±ãå«ãŸããŸãã ãtemporaryã䜿çšãããããfilesortã䜿çšããããªã©ã®å€ã¯ãåé¡ã®ãªã¯ãšã¹ãã瀺ãã€ã³ãžã±ãŒã¿ã§ãã ããã§å¯èœãªå€ã®å®å šãªãªã¹ããèŠã€ããããšãã§ããŸãã
EXPLAINã®åŸãã¯ãšãªã§EXTENDEDããŒã¯ãŒãã䜿çšã§ããMySQLã¯ã¯ãšãªã®å®è¡æ¹æ³ã«é¢ããè¿œå æ å ±ã衚瀺ããŸãã ãã®æ å ±ã衚瀺ããã«ã¯ãEXTENDEDãªã¯ãšã¹ãã®çŽåŸã«SHOW WARNINGSã¯ãšãªãããã«å®è¡ããå¿ èŠããããŸãã ã¯ãšãªã®ãªããã£ãã€ã¶ã«ãã£ãŠå€æŽãè¡ãããåŸã«å®è¡ãããã¯ãšãªã«é¢ãããã®æ å ±ã調ã¹ãã®ãæã䟿å©ã§ãã
EXPLAIN EXTENDED SELECT City.Name FROM City JOIN Country ON (City.CountryCode = Country.Code) WHERE City.CountryCode = 'IND' AND Country.Continent = 'Asia'
********************** 1. row ********************** id: 1 select_type: SIMPLE table: Country type: const possible_keys: PRIMARY key: PRIMARY key_len: 3 ref: const rows: 1 filtered: 100.00 Extra: ********************** 2. row ********************** id: 1 select_type: SIMPLE table: City type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4079 filtered: 100.00 Extra: Using where 2 rows in set, 1 warning (0.00 sec)
SHOW WARNINGS
********************** 1. row ********************** Level: Note Code: 1003 Message: select `World`.`City`.`Name` AS `Name` from `World`.`City` join `World`.`Country` where ((`World`.`City`.`CountryCode` = 'IND')) 1 row in set (0.00 sec)
EXPLAINã«ããããã©ãŒãã³ã¹ã®åé¡ã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã
ããã§ãEXPLAINã³ãã³ãã®åºåãåæããŠãããã»ã©é«éã§ã¯ãªãã¯ãšãªãæé©åããæ¹æ³ãèŠãŠã¿ãŸãããã çŸåšåäœããŠããã¢ããªã±ãŒã·ã§ã³ã«ã¯å€ãã®ããŒãã«ãããããããã®éã«å€ãã®é¢ä¿ãããããšã¯ééããããŸããããã¯ãšãªãèšè¿°ããæé©ãªæ¹æ³ãäºæž¬ããããšã¯é£ããå ŽåããããŸãã
ã€ã³ããã¯ã¹ããã©ã€ããªããŒãæããªãé»ååååŒã¢ããªã±ãŒã·ã§ã³çšã®ãã¹ãããŒã¿ããŒã¹ãäœæããæãããã¯ãšãªã䜿çšããŠããŒãã«ãäœæãããã®ãããªããŸãè¯ããªãæ¹æ³ã®å¹æã瀺ããŸãã ããããããŠã³ããŒãã§ãããã®ããŒãã«ããã³ãããŸã-github.com/phpmasterdotcom/UsingExplainToWriteBetterMySQLQueries
EXPLAIN SELECT * FROM orderdetails d INNER JOIN orders o ON d.orderNumber = o.orderNumber INNER JOIN products p ON p.productCode = d.productCode INNER JOIN productlines l ON p.productLine = l.productLine INNER JOIN customers c on c.customerNumber = o.customerNumber WHERE o.orderNumber = 10101
çµæãèŠããšïŒäžã®äŸã§ã®ã¿èŠãå¿ èŠããããŸããäžã®ãªã³ã¯ã«ã¯æ¢ã«ããŒãè¿œå ããããã³ããå«ãŸããŠããŸãïŒãæªããªã¯ãšã¹ãã®ãã¹ãŠã®çç¶ãèŠãããŸãã
æŽæ° ã€ã³ããã¯ã¹ãªãã®åºå®ãã³ãããããŸãã äœããã®çç±ã§ãå ã®èè ã®ãã³ãã§ã¯ãã€ã³ããã¯ã¹ãæåã«è¿œå ãããŸããã
ããããããè¯ãã¯ãšãªãäœæããŠããã€ã³ããã¯ã¹ãè¿œå ãããŸã§çµæã¯åãã«ãªããŸãã æå®ãããæ¥ç¶ã¿ã€ãã¯ALLïŒææªïŒã§ããã€ãŸããMySQLã¯æ¥ç¶ã§äœ¿çšã§ããåäžã®ããŒã決å®ã§ããŸããã§ããã ã€ãŸããpossible_keysãškeyã¯NULLã§ãã æãéèŠãªããšã¯ãè¡ãã£ãŒã«ãã¯ãMySQLãã¯ãšãªã®åããŒãã«ã®ãã¹ãŠã®ã¬ã³ãŒããã¹ãã£ã³ããããšã瀺ããŸãã ããã¯ã7Ã110Ã122Ã326Ã2996 = 91,750,822,240ã¬ã³ãŒããã¹ãã£ã³ããŠé©åãª4ã€ãèŠã€ããããšãæå³ããŸãïŒã¯ãšãªããEXPLAINãåé€ããèªåã§ç¢ºèªããŸãïŒã ããã¯éåžžã«æªãããããã®ã¬ã³ãŒãã®æ°ã¯ããŒã¿ããŒã¹ã倧ãããªãã«ã€ããŠææ°é¢æ°çã«å¢å ããŸãã
次ã«ãåããŒãã«ã®äž»ããŒãªã©ã®æãããªã€ã³ããã¯ã¹ãè¿œå ããŠãã¯ãšãªãå床å®è¡ããŸãã ãããäžè¬çãªã«ãŒã«ãšããŠãJOINã§äœ¿çšãããåãããŒãè¿œå ããåè£ãšããŠäœ¿çšã§ããŸãã MySQLã¯åžžã«ããããã¹ãã£ã³ããŠãäžèŽããã¬ã³ãŒããèŠã€ããŸãã
ALTER TABLE customers ADD PRIMARY KEY (customerNumber); ALTER TABLE employees ADD PRIMARY KEY (employeeNumber); ALTER TABLE offices ADD PRIMARY KEY (officeCode); ALTER TABLE orderdetails ADD PRIMARY KEY (orderNumber, productCode); ALTER TABLE orders ADD PRIMARY KEY (orderNumber), ADD KEY (customerNumber); ALTER TABLE payments ADD PRIMARY KEY (customerNumber, checkNumber); ALTER TABLE productlines ADD PRIMARY KEY (productLine); ALTER TABLE products ADD PRIMARY KEY (productCode), ADD KEY (buyPrice), ADD KEY (productLine); ALTER TABLE productvariants ADD PRIMARY KEY (variantId), ADD KEY (buyPrice), ADD KEY (productCode);
ã€ã³ããã¯ã¹ãè¿œå ããåŸãåã®ã¯ãšãªãå®è¡ããŸãããã ããã衚瀺ãããŸãïŒ
********************** 1. row ********************** id: 1 select_type: SIMPLE table: o type: const possible_keys: PRIMARY,customerNumber key: PRIMARY key_len: 4 ref: const rows: 1 Extra: ********************** 2. row ********************** id: 1 select_type: SIMPLE table: c type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: ********************** 3. row ********************** id: 1 select_type: SIMPLE table: d type: ref possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 4 Extra: ********************** 4. row ********************** id: 1 select_type: SIMPLE table: p type: eq_ref possible_keys: PRIMARY,productLine key: PRIMARY key_len: 17 ref: classicmodels.d.productCode rows: 1 Extra: ********************** 5. row ********************** id: 1 select_type: SIMPLE table: l type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 52 ref: classicmodels.p.productLine rows: 1 Extra: 5 rows in set (0.00 sec)
ã€ã³ããã¯ã¹ãè¿œå ããåŸãèªã¿åãã¬ã³ãŒãã®æ°ã¯1Ã1Ã4Ã1Ã1 = 4ã«äœäžããŸãããorderdetailsããŒãã«ã®åã¬ã³ãŒãorder_number = 10101ã«ã€ããŠãããã¯MySQLãã€ã³ããã¯ã¹ã䜿çšããŠä»ã®ãã¹ãŠã®ããŒãã«ã§å¯Ÿå¿ããã¬ã³ãŒããèŠã€ããããšãã§ããåãœãŒãããªãã£ãããšãæå³ããŸãå šè¡šã¹ãã£ã³ã«ã
æåã®çµè«ã§ã¯ãçµåã¿ã€ã-ãconstãã䜿çšã§ããŸããããã¯ãè€æ°ã®ã¬ã³ãŒããæã€ããŒãã«ã®æéã®çµåã¿ã€ãã§ãã MySQLã¯ãPRIMARY KEYãã€ã³ããã¯ã¹ãšããŠäœ¿çšã§ããŸããã ãrefããã£ãŒã«ãã«ã¯ããconstãã衚瀺ãããŸããããã¯ãWHEREããŒã¯ãŒãã®åŸã®ã¯ãšãªã§æå®ãããå€10101ã«ä»ãªããŸããã
ãã1ã€ã®èŠæ±ã確èªããŸãã ãã®äžã§ã補åãšproductvariantsã®2ã€ã®ããŒãã«ã®åéåãéžæããããããã補åã©ã€ã³ãšçµã¿åãããŸãã productvariantsãproductCodeãã£ãŒã«ããæã€ããŸããŸãªè£œåãªãã·ã§ã³ã§æ§æãããäŸ¡æ Œãžã®ãªã³ã¯ã§ãã
EXPLAIN SELECT * FROM ( SELECT p.productName, p.productCode, p.buyPrice, l.productLine, p.status, l.status AS lineStatus FROM products p INNER JOIN productlines l ON p.productLine = l.productLine UNION SELECT v.variantName AS productName, v.productCode, p.buyPrice, l.productLine, p.status, l.status AS lineStatus FROM productvariants v INNER JOIN products p ON p.productCode = v.productCode INNER JOIN productlines l ON p.productLine = l.productLine ) products WHERE status = 'Active' AND lineStatus = 'Active' AND buyPrice BETWEEN 30 AND 50
********************** 1. row ********************** id: 1 select_type: PRIMARY table: <derived2> type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 219 Extra: Using where ********************** 2. row ********************** id: 2 select_type: DERIVED table: p type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 110 Extra: ********************** 3. row ********************** id: 2 select_type: DERIVED table: l type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 52 ref: classicmodels.p.productLine rows: 1 Extra: ********************** 4. row ********************** id: 3 select_type: UNION table: v type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 109 Extra: ********************** 5. row ********************** id: 3 select_type: UNION table: p type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 17 ref: classicmodels.v.productCode rows: 1 Extra: ********************** 6. row ********************** id: 3 select_type: UNION table: l type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 52 ref: classicmodels.p.productLine rows: 1 Extra: ********************** 7. row ********************** id: NULL select_type: UNION RESULT table: <union2,3> type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL Extra: 7 rows in set (0.01 sec)
ãã®ã¯ãšãªã«ã¯å€ãã®åé¡ããããŸãã 補åããã³è£œåå€æ°ã®ãã¹ãŠã®ãšã³ããªãã¹ãã£ã³ããŸãã ãªããªã ãããã®ããŒãã«ã«ã¯ãproductLineããã³buyPriceåã®ã€ã³ããã¯ã¹ããããŸãããpossible_keysããã³ããŒãã£ãŒã«ãã«ã¯NULLå€ã衚瀺ãããŸãã 補åããã³è£œåã©ã€ã³ããŒãã«ã®ã¹ããŒã¿ã¹ã¯UNIONã®åŸã«ãã§ãã¯ããããããããããUNIONå ã«ç§»åãããšã¬ã³ãŒãã®æ°ãæžããŸãã ã€ã³ããã¯ã¹ãè¿œå ããŸãã
CREATE INDEX idx_buyPrice ON products(buyPrice); CREATE INDEX idx_buyPrice ON productvariants(buyPrice); CREATE INDEX idx_productCode ON productvariants(productCode); CREATE INDEX idx_productLine ON products(productLine);
EXPLAIN SELECT * FROM ( SELECT p.productName, p.productCode, p.buyPrice, l.productLine, p.status, l.status as lineStatus FROM products p INNER JOIN productlines AS l ON (p.productLine = l.productLine AND p.status = 'Active' AND l.status = 'Active') WHERE buyPrice BETWEEN 30 AND 50 UNION SELECT v.variantName AS productName, v.productCode, p.buyPrice, l.productLine, p.status, l.status FROM productvariants v INNER JOIN products p ON (p.productCode = v.productCode AND p.status = 'Active') INNER JOIN productlines l ON (p.productLine = l.productLine AND l.status = 'Active') WHERE v.buyPrice BETWEEN 30 AND 50 ) product
********************** 1. row ********************** id: 1 select_type: PRIMARY table: <derived2> type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 12 Extra: ********************** 2. row ********************** id: 2 select_type: DERIVED table: p type: range possible_keys: idx_buyPrice,idx_productLine key: idx_buyPrice key_len: 8 ref: NULL rows: 23 Extra: Using where ********************** 3. row ********************** id: 2 select_type: DERIVED table: l type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 52 ref: classicmodels.p.productLine rows: 1 Extra: Using where ********************** 4. row ********************** id: 3 select_type: UNION table: v type: range possible_keys: idx_buyPrice,idx_productCode key: idx_buyPrice key_len: 9 ref: NULL rows: 1 Extra: Using where ********************** 5. row ********************** id: 3 select_type: UNION table: p type: eq_ref possible_keys: PRIMARY,idx_productLine key: PRIMARY key_len: 17 ref: classicmodels.v.productCode rows: 1 Extra: Using where ********************** 6. row ********************** id: 3 select_type: UNION table: l type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 52 ref: classicmodels.p.productLine rows: 1 Extra: Using where ********************** 7. row ********************** id: NULL select_type: UNION RESULT table: <union2,3> type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL Extra: 7 rows in set (0.01 sec)
ã芧ã®ããã«ãçµæãšããŠãã¹ãã£ã³ãããã©ã€ã³ã®æ°ã¯2,625,810ïŒ219Ã110Ã109ïŒãã276ïŒ12Ã23ïŒã«æžå°ããŸãããããã¯ããã©ãŒãã³ã¹ã®åªããã²ã€ã³ã§ãã ã€ã³ããã¯ã¹ãè¿œå ããçŽåŸã«ã¯ãšãªå ã§ä»¥åã®é åãªãã§åãã¯ãšãªãå®è¡ããå Žåãã¹ãã£ã³ãããè¡ã«ãã®ãããªæžå°ã¯èŠãããŸããã 掟ççµæã§WHEREã䜿çšãããŠããå ŽåãMySQLã¯ã€ã³ããã¯ã¹ã䜿çšã§ããŸããã ãããã®æ¡ä»¶ãUNIONå ã«é 眮ãããšãã€ã³ããã¯ã¹ã䜿çšã§ããããã«ãªããŸãã ããã¯ãã€ã³ããã¯ã¹ãè¿œå ããã ãã§ã¯å¿ ãããååã§ã¯ãªãããšãæå³ããŸãã é©åãªã¯ãšãªãèšè¿°ãããŸã§ãMySQLã¯ãããã䜿çšã§ããŸããã ïŒhttp://www.php.su/mysql/manual/?page=MySQL_indexes-è¿œå æ å ±ïŒã
ãŸãšã
ãã®èšäºã§ã¯ãEXPLAINããŒã¯ãŒããåºåã«é¢ããæ å ±ãããã³ã³ãã³ãã®åºåã䜿çšããŠã¯ãšãªãæ¹åããæ¹æ³ã®äŸã«ã€ããŠèª¬æããŸãã çŸå®ã®äžçã§ã¯ããã®ã³ãã³ãã¯ãèæ ®ãããŠããã·ããªãªããã圹ç«ã€å ŽåããããŸãã ã»ãšãã©ã®å ŽåãWHEREã䜿çšããè€éãªæ§é ã䜿çšããŠäžé£ã®ããŒãã«ãçµåããŸãã åæã«ãåã«ããŒãã«ã«ã€ã³ããã¯ã¹ãè¿œå ããã ãã§ã¯ãå¿ ãããç®çã®çµæãåŸããããšã¯éããŸããã ãã®å Žåããªã¯ãšã¹ãã確èªããå¿ èŠããããŸãã