åºãæµ
ããæ
å½ãã¦ã¾ããota ã§ãã
æè¡ããã°ç¬¬ä¸åããæ©éæµç¨ã¹ã©ã¤ãã§ç³ã訳ããã¾ãããã社å
åå¼·ä¼è³æã¨ãã¦ä½æãããMySQL INDEX + EXPLAINå
¥éãã§ãã
å½ç¤¾ã§ãã½ã¼ã·ã£ã«ã²ã¼ã ã®éçºãè¡ã£ã¦ãã¾ããããã®ãããªå¤§éã®ãã¼ã¿ã使ç¨ããã»ã¯ã¨ãªã®é度ãæ±ããããå ´åã«ã¤ã³ããã¯ã¹ã¯å¤§å¤éè¦ã§ãã
ã¤ã³ããã¯ã¹ã®æå¹ãªå©ç¨ã«ã¯DBè¨è¨è
ã ãã§ã¯ãªãããã°ã©ãã«ãããç¨åº¦ã®ç¥èãæä½éå¿
è¦ã¨ãªãã¾ãããã¤ã³ããã¯ã¹ã«ã¤ãã¦ã®åå¿è
åãè³æããã¾ããªãããã§ãã
ãã®ã¹ã©ã¤ãã§ã¯ããã°ã©ãã«ç¥ã£ã¦ããã¦æ¬²ãã以ä¸ã®åºæ¬çãªç¹ãã¾ã¨ãã¾ãããã
- INDEXã使ç¨ããæã«æ°ãã¤ãããã¨
- WHEREå¥
- !=ã<>ã¯ã¤ã³ããã¯ã¹ã使ç¨ã§ããªã
- WHEREå¥ã®å ¨ã¦ã®ANDã«ããã£ã¦ããªãã¤ã³ããã¯ã¹ã¯ä½¿ç¨ãããªã
- ææ§æ¤ç´¢æãå®æ°æååï¼åæ¹ä¸è´ä»¥å¤ã§ã¯ã¤ã³ããã¯ã¹ã使ç¨ã§ããªã
- è¤åã¤ã³ããã¯ã¹ã¨ã¤ã³ããã¯ã¹ãã¼ã¸ã®éãã«ã¤ãã¦
- ãã®ä»ORDER BYå¥ãHAVINGå¥ã«ã¤ãã¦
- WHEREå¥
- INDEXãä½æããæã«æ°ãã¤ãããã¨
- é¸ææ§ã®é«ãé ç®ãã¤ã³ããã¯ã¹ã«ãã
- è¤åã¤ã³ããã¯ã¹ã¯å é ããé ã«é¨åã¤ã³ããã¯ã¹ã¨ãã¦ã使ç¨ã§ãã
- ã¤ã³ããã¯ã¹ãµã¤ãºãå¢ãããªãã»å¢ãããã¨ã«ããå½±é¿
- EXPLAINåºåçµæããã§ããSQLãã¥ã¼ãã³ã°
- è¦ãã¹ãé¨åã¯typeãkeyãrowsãExtra
ãã¼ã¿ä½æã«ä½¿ç¨ããåºæ¬ã®ãã¼ãã«ã¯ä»¥ä¸ã®ãããªãã®ã§ãã
CREATE TABLE IF NOT EXISTS test_tbl ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, col_1 int(11) NOT NULL, col_2 varchar(20) COLLATE utf8_unicode_ci NOT NULL, col_3 int(11) NOT NULL, col_4 int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ãã¼ãã«ã®åã«ã©ã ã«ã¯ 0ã1,000,000 ã®å¤ãå ¥ãã¦ãã¾ãã
ã追è¨ã
äºæ³ä»¥ä¸ã«å¥½è©ãªãããªã®ã§ãæµãæ¸ãã ã£ã ORDER BY ã«ã¤ãã¦ãä¾ã追å ãã¾ããã
ä¸ã®ã¹ã©ã¤ããå¤ãã¾ã¾ï¼è¡¨ç´å³ä¸ã®æ´æ°æ¥æã4/1ã§ãªãå ´åå¤ãï¼ã®å ´åã¯ç´æ¥SlideShareã¸é£ãã§ãã ããã(4/1)