비트코인 사이트 긁어다가 뭐좀 할게 있어서 ..
하루에 100만개 데이터를 저장해서 .. 끌어오는 중입니다..
mysql workbench 에서는
select id FROM bitrex_nt where market = 'BTC-GEO' and created_at >= date_add(now(),interval -4 hour) group by rank
해당 쿼리가 .. 0.03초 정도 걸립니다... 코인이름마다 조금씩 차이는 있지만 0.0x 대로 끝납니다..
그런데 .. 웹이랑 붙여서 가져오는데 .. 7초가 넘어도 안나오길래 서버로 직접 들어가서 mysql 커맨드 클라이언트로
같은 쿼리를 날리면.. 8~9초가 걸리네요...
다시 workbench 와서 .. 해보면.. 0.0x대구요 ... 혹시 캐시 때문에 그런가 싶어서 workbench 다시 실행 하고 ..
-4 시간을 24시간 market 네임도 바꿔보고 해도 .. 0.0x 대에 결과가 금방 나옵니다..
근데 서버 들어가서 하면... 6~8초 등등 엄청 오래 걸리네요 ㅜㅜ
MariaDB [cryptocoin]> select id FROM bitrex_nt where market = 'BTC-GEO' and created_at >= date_add(now(),interval -4 hour) group by rank;
+---------+
| id |
+---------+
| 2203074 |
| 2225053 |
| 2192782 |
| 2246441 |
| 2249412 |
| 2253576 |
| 2264269 |
+---------+
7 rows in set (10.51 sec)
위는 mysql
아래는 workbench 입니다.
17:32:02select id FROM bitrex_nt where market = 'BTC-GEO' and created_at >= date_add(now(),interval -4 hour) group by rank LIMIT 0, 500007 row(s) returned0.031 sec / 0.000 sec
왜 이런걸까요? ㅜㅜ 쿼리 캐시라면.. workbench 도 빠르고 mysql에서도 빨라야 할것 같은데 말입니다.
무엇때문에 이런 현상이 나는지 짐작 가는거 있으시면 답변좀 부탁 드릴게요.
Workbench Preferences. ¿¡¼ SQL Editor ÅÇ Under SQL Execution ¿¡¼ Limit Rows°¡ üũµÇ¾îÀÖ´ÂÁö ÇѹøÈ®ÀÎÇغ¸½Ã¸é È®½ÇÇÒ°Å°°³×¿ä
Äõ¸®¸¦ ÅøÀÌ ÀÚüÀûÀ¸·Î ¿ÉƼ¸¶ÀÌÁîÇϰųª °á°ú°¡ ij½ÌµÇ´Â°Ô¾Æ´Ï¶ó¸é cuiȯ°æº¸´Ù ´õºü¸¦¼ö°¡ÀÖ³ª¿ä??
explain ¸í·ÉÀ¸·Î Äõ¸®¸¦ »ìÆ캸°í, °³¼±ÇÏ´Â ¹æ¹ýÀÌ ¿ì¼±ÀÏ°Í °°±¸¿ä.
Àú°°Àº°æ¿ì, ÇÑ Å×À̺í·Î ¸î¹é¸¸¾¿ ½×¾ÆµÎÁø ¾Ê°í(Àú¸¸ ±×·±Áø ¸ð¸£°ÚÁö¸¸ row¼ö°¡ ¹é¸¸´ÜÀ§·Î ³Ñ¾î°¡¸é ²Ï ´À·ÁÁö´õ¶ó±¸¿ä), ³¯Â¥º°·Î Å×À̺íÀ» µû·Î Â¥±âµµ ÇÏ°í,
Á¶È¸¿ë Å×À̺íÀ» µû·Î ¸¸µé¾î¼ ÀúÀåÇϱ⵵ Çϱ¸¿ä.
¹é¸¸ÀÌ ³Ñ´Â Å×ÀÌºí¿¡¼ Á÷Á¢ÀûÀ¸·Î selectÇϴ°ÍÀº ±× ºóµµ°¡ ±²ÀåÈ÷ Àûµµ·Ï ¶Ç´Â, ½Ã°£ÀÌ °É·Áµµ »ó°ü¾ø´Â ÀÛ¾÷¿¡¸¸ »ç¿ëÇÏ°í ÀÖ¾î¿ä.
created_at ¶û market µÎ°³ º¹ÇÕÀ妽º·Î Áá´õ´Ï .. 0.0´ë·Î µé¾î¿Í¼ .. ÀÌÁ¦ µÆ³× .. ÇÏ°í »ç¿ëÇÒ·Á´Â Âû¶ó¿¡
À¥¿¡¼ »Ñ·ÁÁִµ¥ ¾öû ´À¸®±æ·¡ º¸´Ï±î .. Áö±Ý ÀÌ»óȲÀ̳׿ä.. workbench ¿¡¼´Â ºü¸£°í ..
mysql Ŭ¶óÀ̾ðÆ®¿¡¼´Â ´À¸®°í¿ä.
¾Ë¼ö ¾ø´Â Çö»óÀ̳׿ä.
explain ¸í·ÉÀ¸·Î µÎ ȯ°æ¿¡¼ planÀÌ ´Ù¸£°Ô µ¿ÀÛÇÏ´ÂÁö È®ÀÎÇØ º¸¼¼¿ä.
±Ùµ¥ .. Á» ÀǾÆÇÑ°Ô .. explain ¸í·É¾î¸¦ Àß º¸Áú ¸øÇؼ ±×·¯´ÂÁö ¸ð¸£°Ú½À´Ï´Ù¸¸
select type table type possible_keys key keylength ref row Extra
SIMPLE bitrex_nt ALL created 2370886 Using where;Usingtemporary,Usingfilesort
ÀÌ·¸°Ô ³ª¿É´Ï´Ù Á¦°¡ ÁÞ¾î µè±â·Ð type ¿¡ ALL ÀÌ ³ª¿À¸é Ç®¼Ä¡·Î ¾öû ´À·Á¾ß ÇÏ´Â°Ô ¾Æ´Ñ°¡¿ä?
group by ¸¦ »©¸é
key created key len 89
row 585062
Extra Using where;Using index
·Î ¶ß°í 0.047 ÃÊ°¡ °É¸³´Ï´Ù.
¼¹öÂÊÀº explain °á°ú´Â ¶È°°ÀÌ ³ª¿À¸ç
½Ã°£Àº 9.51 ÃÊ°¡ °É¸®³×¿ä.
¶È°°Áø ¾ÊÁö¸¸, ºñ½ÁÇÑ È¯°æÀ¸·Î ¸¸µé¾îµÎ°í Å×½ºÆ® Çغ¸°í Àִµ¥, limit¸¦ ÁÖ°í/¸»°íÀÇ Â÷ÀÌ ¸»°í´Â ¼º´É Â÷°¡ ¾ø³×¿ä.
¸»¾¸µ¥·Î .. limit ¸¦ ºÙ¿©ÁÖ´Ï .. ¼Óµµ°¡ »¡¶óÁ³½À´Ï´Ù workbench ¸¸ÅÀÌ¿ä ..
limit ´Â.. ÃÖÁ¾°ª¿¡ ÀϺκи¸ °¡Á®¿À´Â°É·Î ¾Ë°í Àִµ¥ .. ¹¹ ´Ù¸¥ ±â´ÉÀÌ Àִ°ǰ¡¿ä?
group by ¾øÀÌ Äõ¸®Çϸé 800 °³ °¡·® ³ª¿À°í .. group by Çϸé 7°³°¡ µÇ´Âµ¥ ... ÀÌ·¸°Ô Çϸé 9ÃÊ °¡·® °É¸®´Âµ¥ ..
µÚ¿¡ limit 10À̵ç 5000 ÀÌµç ºÙÀ̸é.. 0.03 ÃÊ¸é ³¡³ª³×¿ä?
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
| id | market | spread | added | change | dayhighprice | daylowprice | lastprice | volume | rank | currency | symbol | created_at |
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
| 2377492 | BTC-GNO | 0.3% | 2017-04-28 | 3.4% | 0.008822450 | 0.008417040 | 0.008800000 | 9.8420 | 147 | Gnosis | GNO | 2017-11-08 17:45:22 |
| 2377295 | BTC-GNO | 0.3% | 2017-04-28 | 3.7% | 0.008822450 | 0.008417040 | 0.008822450 | 9.8420 | 148 | Gnosis | GNO | 2017-11-08 17:45:03 |
| 2288790 | BTC-GNO | 2.1% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763300 | 9.3500 | 149 | Gnosis | GNO | 2017-11-08 15:43:50 |
| 2284435 | BTC-GNO | 2.1% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763300 | 9.3500 | 150 | Gnosis | GNO | 2017-11-08 15:37:37 |
| 2268596 | BTC-GNO | 0.3% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763160 | 9.2090 | 151 | Gnosis | GNO | 2017-11-08 15:16:40 |
| 2264835 | BTC-GNO | 0.3% | 2017-04-28 | 3.0% | 0.008789260 | 0.008417040 | 0.008763090 | 8.9300 | 152 | Gnosis | GNO | 2017-11-08 15:11:53 |
| 2248006 | BTC-GNO | 0.1% | 2017-04-28 | 0.9% | 0.008770000 | 0.008417040 | 0.008763020 | 8.8170 | 153 | Gnosis | GNO | 2017-11-08 14:48:30 |
| 2245631 | BTC-GNO | 0.1% | 2017-04-28 | 0.9% | 0.008770000 | 0.008417040 | 0.008763020 | 8.7760 | 154 | Gnosis | GNO | 2017-11-08 14:45:16 |
| 2242662 | BTC-GNO | 0.1% | 2017-04-28 | 0.8% | 0.008770000 | 0.008417040 | 0.008763020 | 8.6290 | 155 | Gnosis | GNO | 2017-11-08 14:41:13 |
| 2241277 | BTC-GNO | 2.6% | 2017-04-28 | 0.8% | 0.008760000 | 0.008417040 | 0.008760000 | 8.4630 | 156 | Gnosis | GNO | 2017-11-08 14:39:28 |
| 2229993 | BTC-GNO | 2.7% | 2017-04-28 | 0.8% | 0.008760000 | 0.008417040 | 0.008759990 | 8.1280 | 158 | Gnosis | GNO | 2017-11-08 14:23:22 |
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
11 rows in set (0.03 sec)
MariaDB [cryptocoin]> select * FROM bitrex_nt where market = 'BTC-GNO' and created_at >= date_add(now(),interval -4 hour) group by rank;
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
| id | market | spread | added | change | dayhighprice | daylowprice | lastprice | volume | rank | currency | symbol | created_at |
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
| 2377492 | BTC-GNO | 0.3% | 2017-04-28 | 3.4% | 0.008822450 | 0.008417040 | 0.008800000 | 9.8420 | 147 | Gnosis | GNO | 2017-11-08 17:45:22 |
| 2377295 | BTC-GNO | 0.3% | 2017-04-28 | 3.7% | 0.008822450 | 0.008417040 | 0.008822450 | 9.8420 | 148 | Gnosis | GNO | 2017-11-08 17:45:03 |
| 2288790 | BTC-GNO | 2.1% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763300 | 9.3500 | 149 | Gnosis | GNO | 2017-11-08 15:43:50 |
| 2284435 | BTC-GNO | 2.1% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763300 | 9.3500 | 150 | Gnosis | GNO | 2017-11-08 15:37:37 |
| 2268596 | BTC-GNO | 0.3% | 2017-04-28 | 0.9% | 0.008789260 | 0.008417040 | 0.008763160 | 9.2090 | 151 | Gnosis | GNO | 2017-11-08 15:16:40 |
| 2264835 | BTC-GNO | 0.3% | 2017-04-28 | 3.0% | 0.008789260 | 0.008417040 | 0.008763090 | 8.9300 | 152 | Gnosis | GNO | 2017-11-08 15:11:53 |
| 2248006 | BTC-GNO | 0.1% | 2017-04-28 | 0.9% | 0.008770000 | 0.008417040 | 0.008763020 | 8.8170 | 153 | Gnosis | GNO | 2017-11-08 14:48:30 |
| 2245631 | BTC-GNO | 0.1% | 2017-04-28 | 0.9% | 0.008770000 | 0.008417040 | 0.008763020 | 8.7760 | 154 | Gnosis | GNO | 2017-11-08 14:45:16 |
| 2242662 | BTC-GNO | 0.1% | 2017-04-28 | 0.8% | 0.008770000 | 0.008417040 | 0.008763020 | 8.6290 | 155 | Gnosis | GNO | 2017-11-08 14:41:13 |
| 2241277 | BTC-GNO | 2.6% | 2017-04-28 | 0.8% | 0.008760000 | 0.008417040 | 0.008760000 | 8.4630 | 156 | Gnosis | GNO | 2017-11-08 14:39:28 |
| 2230389 | BTC-GNO | 2.7% | 2017-04-28 | 0.8% | 0.008760000 | 0.008417040 | 0.008759990 | 8.1280 | 158 | Gnosis | GNO | 2017-11-08 14:23:52 |
+---------+---------+--------+------------+--------+--------------+-------------+-------------+--------+------+----------+--------+---------------------+
11 rows in set (6.72 sec)
°É¸®³×¿ä .. ÀÌ°Å ¹«Ã´ Ç㹫Çѵ¥ .. ¤Ì¤Ì
https://books.google.co.kr/books?id=IagfgRiKWd4C&pg=PA203&lpg=PA203&dq=limit+Fetching+more+rows+than+needed+mysql&source=bl&ots=w_a0j-QzFg&sig=ut8KOyA6-hKxpjHUnY9VC2Bal3k&hl=ko&sa=X&ved=0ahUKEwjo-ozY1q7XAhUME7wKHVnVBRIQ6AEIRjAH#v=onepage&q=limit%20Fetching%20more%20rows%20than%20needed%20mysql&f=false
ÀÌ Ã¥ ³»¿ëÀÌ ¼³¸íÇϴ³»¿ëÀÌ ¸ÂÁö¾ÊÀ»±î½Í½À´Ï´Ù
±×·±µ¥ ..limit ´Â.. Á¦ °á°ú°ªÀÌ 7 °³¸é.. limit 5ÁáÀ»¶§ 5°³¸¸ º¸¿©Áִ°Š¾Æ´Ñ°¡¿ä?
°á°ú°ªÀÌ 7 °³ Àε¥.. limit ¸¦ ¾ÈÁ༠¾öû ´À·ÁÁø´Ù°Å³ª
7°³ °á°ú°ªÀε¥ .. limit 100 ÀÌ·±½ÄÀ¸·Î ÁÖ¸é »¡¶óÁö´Â ÀÌÀ¯°¡ ¿Ö±×·±°ÇÁö ¾Ë ¼ö ÀÖÀ»±î¿ä ..
³· ºÎÅÍ »ðÁúÇÑ ºÎºÐÀ̶ó ... ¿Ö±×·±Áö ¾Ë¼ö ÀÖÀ¸¸é ¾Ë°í ½Í³×¿ä..
limit 100À» °É¾ú´Ù¸é, select Á¶°Ç¿¡ µû¶ó¼ limit °É¸°°Í ±îÁö¸¸ ¿¬»êÇÏ°í °á°ú¸¦ ¹Ù·Î º¸³»ÁØ´Ù°í ¾Ë°í ÀÖÀ¸´Ï±î¿ä.
Àú Ã¥¿¡µµ ±×³É Äõ¸®¸¦ ¾²¸é Àüü¸¦ ¿¬»êÇÏ¿© º¸¿©Áִϱî, limit¸¦ »ç¿ëÇÏ´Â°Ô ÁÁÀº ¹æ¹ýÀÌ´Ù ¶ó°í ½áÁ®ÀÖ±äÇÏÁö¸¸...
°á°ú°ªÀÌ 100µµ ¾ÈµÉ¶§´Â, Àüü¸¦ ¿¬»êÇÒÅÙµ¥.. ¹º »óȲÀÎÁö ¸ð¸£°Ú³×¿ä.
Ã¥³»¿ë°ú
http://gubug.tistory.com/m/446 ÀÌ Æ÷½ºÆ®³»¿ëÀ» º¸¸é
LimitÀ» °Å´Â°Í¸¸À¸·Îµµ ¾î´ÀÁ¤µµ ¿ÉƼ¸¶ÀÌ¡ÀÌ ³»ºÎ¿¡¼ ÀÌ·ïÁö´Â°ÍÀº¾Æ´ÑÁö...
½Ã¿øÇÑ ÇØ´äÀÌ Àúµµ ±Ã±ÝÇϳ׿ä
À¥¿¡¼ °á°ú°Ç¼ö°¡ 3000°³¸¸ µÇ¾îµµ ºê¶ó¿ìÁ®´Â Á×À»¼öµµ Àְųª °øÆ÷ÀÇ ÀÀ´ä´ë±â »óÅ¿¡¼ ±ú¾î³ªÁö.¸øÇÏ´Â ½ÌÅ°¡.µÇ±âµµ ÇÕ´Ï´Ù.limit ·Î ȸé ÆäÀÌ¡ ÇÒ ¼ö ÀÖµµ·Ï º¯°æÇØÁֽô °ÍÀÌ ÁÁÀ»µí ÇÕ´Ï´Ù.
limit °¡ ÇÊ¿ä¾ø´Â »óȲÀ̶ó ¾È½è´õ´Ï .. 6~9ÃÊ ´Ù¾çÇÏ°Ô ´À·Á¼ ...
Áú¹® µå¸°°Çµ¥ ...
7°ÇÀÌ ´ÙÀÎ Äõ¸®¿¡ limit 100ÀÌ´ø 1000 ÀÌ´ø ´Þ¸é.. 0.03 ÃÊ·Î ¾öû »¡¶óÁý´Ï´Ù...
Àú¿ª½Ã .. °á°úÀÇ.. ¼ö¸¦ Á¦ÇÑ ÇÏ´Â ±â´É¸¸ ÇÏ´ÂÁÙ ¾Ë¾Ò´Âµ¥ .. ´Ù¸¥ ¼û°ÜÁø ±â´ÉÀÌ ÀÖ³ª ±Ã±ÝÇϳ׿ä.
½ÇÁ¦ º¸¿©ÁÙ °á°ú°ªÀÌ 7°³¶ó¸é TOP 7 Á¦ÇÑÀ» °ÉÁö ¾ÊÀ¸¸é ´À·ÁÁö´Â°Ç ´ç¿¬ÇÑ°Ì´Ï´Ù. DB°¡ óÀ½¿£ °Ç¼ö°¡ ¸¹Áö ¾ÊÀ¸¸é º°·Î ¸ø´À³¢°ÚÁö¸¸ ½Ã°£ÀÌ È带¼ö·Ï µ¥ÀÌÅÍ·®ÀÌ Ä¿Áö¸é ¾öû ´À·ÁÁý´Ï´Ù. °Ç¼ö¸¦ Á¦ÇÑÇÏÁö ¾ÊÀ¸¸é Àüü°Ç¼ö¸¦ Á¶È¸ÇÏ°í 7°³¸¸ »Ñ·ÁÁÙ¶§´Â Àüü¸¦ ±Ü¾î¿À´Â°Å¶û °°Àº ÀÌÄ¡ÀÔ´Ï´Ù. ÇÏÁö¸¸ Äõ¸®¿¡ 7°³¸¸ Á¦ÇÑÀ» °É¸é À妽º Ÿ°í °á°ú°ª º¸¿©ÁÙ Æ®·¡ÇÈ ¾ø°í ÇÏ¸é ¼ø½Ä°£¿¡ ¶ã°Ì´Ï´Ù.