å ¥ç¤¾ãã¾ããã
æ ªå¼ä¼ç¤¾ãã¯ã·ã£ã®ç¤¾å
è¦åã«ã²ã£ãããçºã社åã¯ãããã¾ãããå
¥ç¤¾ãã¾ããã
ãããããé¡ããã¾ãã
追è¨ï¼åä¹ã£ã¦ããããã ã£ã¦ï¼ã§ããçãããã£ã¦ãããåä¹ã£ã¡ããããªãäºã«ãã¦ããã¾ããâ¦
æ ªå¼ä¼ç¤¾ECãããéè·ãã¾ãã
ããã5å¹´ãã²ãããä¸è©±ããã¦é ããECãããéè·ãã¦ãã¾ã£ãäºãå ±åãã¾ãã
ç®ä¸ã®æ©ã¿ã¯ãããã£ã¼ã«ç»åãã¨ã³ããã¨ããååãã©ããããã§ãã
æ¶ãå»ã£ãå¾ã«çµé¨å¤ãå ¥ããªãã¨ããäºã¯ééããäºå®èªä½ãæ¶ãå»ã£ã¦ããã®ã ããããåãæ¶ãããã®åã¯åã®äºãªãã¦è¦ãã¡ãããªãã¨ããã®ããï¼
DevOpsã®è©±é¡ãå
é±ç±ãã£ããECããã¯Devã¨Opsã®å£ãå²ã¨é«ãæãããããä½ããããã¨ãã度ã«ããããOpsã¨ç¢ºèªããã説å¾ããªãããããªãã®ãâ¦ãã¿ãããªææ
ã«ãªãã®ã§ãããªãã§ãããOpsã®æ¹ã
ãä¼¼ããããªäºãæã£ã¦ãããããã®ã§ããããæ¹åãã¦ãããªãã¨ãã¡ã§ããããããã³ã®æ大åããããã³çµçµæã
DevOpsã®æåã¨ãªããã¼ã¯ã¼ãã
- å°æ¬
- ä¿¡é ¼
- 失æã許容ãã
- 責ããªã
話ãå¤ãããã©ã1å¹´ã»ã©æå±ãã¦ããäºæ¥é¨ãä¸æããããªãæãã ã£ãã®ã§äºæ¥ç¸®å°ãã¦ãã¾ã£ããæ®å¿µã ãã©ãéã稼ããªãã£ããªããããããªãã§ããããéãã¡ã«ãªããããªã¼ããéãã¡ã«ãªã£ã¦ã·ã£ã¬ãªããªãã¼ã¨ãçµå¶ããããªã¼ããéæã¡ã«ãªãã¨ãã¼ã¨ãã«ãã§ã¨ãçµå¶ãã¦ãããããããªããªãã®ããªã¼ãåã¯ããããããªãææ§ã¯å¤±ããããªãã®ã§ãã£ã±å¹³æ°ã§ãããã¨æãã¾ããã
æè¿ãå»ã人ãå¤ãã¦ã
ãããã
ããã©ã ããã¦å ã®å½¼æ¹ã¸æ¶ãå»ããã¨ãã¦ãã人ã«è§¦ãã¦ããã¨ã©ããªãã®ã ããã
æ¥ã«ã©ã³ãã³ã°éè¨ãããã¨ã«ãªã£ã¦ãã¾ã£ããã¼ã¿ã®ä½æã極åMySQLã ãã§ããã
ã¨ã¤ããããã®æ©è½ã«ã¦ã¼ã¶ã©ã³ãã³ã°ã欲ãããããªãã¯ãã§ããã¡ããæ´æ°ééãçããªãã¤ãå½æ¥ã®ã©ã³ãã³ã°ã¨ãã¤ãªã¼ã©ã³ãã³ã°ããã¨ãããªããã¿ãããªä¾é ¼ããããäºãå¤ãæ¥åããã¦ããã¾ãã
ãããªæã¯ã¨ããããæ¢åã®è³æºã ãã§ä½ã¨ãããªãããããªãã®ã§ãé å¼µã£ã¦SQLã¨ããããªããã°ã©ã ã§å¯¾å¿ããããã¦ããã¾ãã
ã¨ããããã©ã³ãã³ã°ã§åºããããã¼ã¿ä¾
é ä½, ç¹æ° 1, 100 2, 98 3, 97 3, 97 5, 95
ã¦ãªæãã§åä½ãããããã¡ããã¨ä½ãä½ãããã»ãã説æã§ããªããã©ãã¢ã¬ã£ã½ãããã
hogeãnååå¾ãã度㫠insert ã§ã¬ã³ã¬ã³è¿½å ãã¦ããè¬ã® user_hoge_nums ãã¼ãã«
desc user_hoge_nums; +------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | user_id | int(10) unsigned | NO | MUL | NULL | | | num | int(10) unsigned | NO | | 0 | | | created | datetime | NO | MUL | NULL | | | updated | datetime | NO | | NULL | | +------------+---------------------+------+-----+---------+----------------+
ã¨ããããæå®ããæé(å½æ¥åã¨ãåæ¥åã¨ã)ãæå®ãã¦ã¹ã³ã¢ãã¦ã¼ã¶æ¯ã«è¨ç®ããSQLã
ãããããã®SQLãªã3000ä¸ã¬ã³ã¼ããããã§ã30ç§ã»ã©ã§å¦çã§ãã¾ããã
select user_id, sum(num) total_score from user_hoge_nums where created between ? and ? group by user_id;
ä¸è¨SQLã§åå¾ãããã¼ã¿ãä¸æçã«æ ¼ç´ãã tmp_hoge_scores ããã
desc tmp_hoge_scores; +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | user_id | int(10) unsigned | NO | UNI | NULL | | | score | int(10) unsigned | NO | | NULL | | +-------------+------------------+------+-----+---------+----------------+
ååã®å¦çãã¼ã¿ãæ®ã£ã¦ãã®ã§ãç殺ãããã
truncate tmp_hoge_scores;
ã²ãããæ®éã« insert ããã10件ã100件åä½ããã㧠commit ããã®ãããã¨æãã¾ããå ¨ä»¶ã¾ã¨ã㦠insert ã㦠commit ã¯ã¤ããããã
insert into tmp_hoge_scores(user_id, score) values(?, ?);
ä¸æçã«éè¨ããã©ã³ãã³ã°ãæ ¼ç´ãã tmp_hoge_rankings ããã
desc tmp_hoge_rankings; +-------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | user_id | int(10) unsigned | NO | UNI | NULL | | | score | int(10) unsigned | NO | | NULL | | | rank | int(10) unsigned | NO | MUL | NULL | | | created | datetime | NO | | NULL | | | updated | datetime | NO | | NULL | | +-------------+---------------------+------+-----+---------+----------------+
ãããååã®å¦çãã¼ã¿ãæ®ã£ã¦ãã®ã§ç殺ãã
truncate tmp_hoge_rankings;
ユーザ定義変数ã£ã¦ãã¤ã使ãã
set @rank:=0, @rownum:=0, @prevalue:=0; insert into tmp_hoge_rankings(user_id, score, rank) select user_id, score, rank from ( select user_id, score, @rank:=if((@rownum:=@rownum+1) and (@prevalue <=> score), @rank, @rownum) as rank, @prevalue:=score as preval from tmp_hoge_score order by score desc ) a;
ä¸æè°ãªæãã®é¨åã ãå解ãã¦è§£èª¬ããã¨ã@prevalue(åã®ã¬ã³ã¼ãã®ã¹ã³ã¢)ã score(ç¾å¨ã®ã¬ã³ã¼ãã®ã¹ã³ã¢)ã¨çãããã° @rank ããéãã° @rownum ã« 1 足ãããã®ã @rank ã«ã»ããã
@rank:=if((@rownum:=@rownum+1) and (@prevalue <=> score), @rank, @rownum)
ããããäºã§åä½ãç¶ããå¾ã«ã@rownum ã«ã¬ã³ã¼ãæ°ãã«ã¦ã³ãã¢ããããã¦ããã®ã§ããªããã¢ã¬ãªé ä½ãåå¾ã§ããã
@prevalue:=score as preval
âç¾å¨ã®ã¬ã³ã¼ãã®ã¹ã³ã¢ã @prevalue ã«ã»ãã
æå¾ã« tmp_hoge_rankings ã hoge_rankings ã«ã hoge_rankings ã tmp_hoge_rankings ã« rename ãã¦ãããã
rename table hoge_rankings to hoge_rankings_backup, tmp_hoge_rankings to hoge_rankings, hoge_rankings_backup to tmp_hoge_rankings;
ã¨ã¾ãããããªæãã®æ¹æ³ã§éè¨ãããã¼ã¿ã«ãã£ã¦è¥å¹²å¤æ´ããã¤ã¤ãã£ã¦ããã¾ããéè¨ã«ãããæéã¯3000ä¸ã¬ã³ã¼ãã§1ååå¾ã§ããããããã§5åããã10åãããããã§ãªãéç¨ã§ããã¬ãã«ã§ãã
ããã¡ããæ©ãããããã°éè¨é¨åã¯ååã®éè¨æããã®ãã¼ã¿ãã¨ã£ã¦ãã¦ãååã®éè¨ãã¼ã¿ã¨è¶³ãã¦ãããªã©ããã°ãããã¨ã
ãããã
æ»æãããããªããå±ããããã©ã ãããã«ã³ã¿ã§ã¯ãè¿ãããã¨ãè© å±æããå¼±ã£ã¦ããã®ã§å ã®å½¼æ¹ã¸è¡ã£ã¦ãã¾ããããããªããæ°ãã¤ãã¾ãããã
TSUTAYAã«å»¶æ»ãã¦ãã漫ç»ãè¿ãããã¨ã¦ãã¤ããä½é¨ã ã£ãã®ã§å¤ãã¯èªãã¾ããã
ãã°ã©ã¤ããé 調ã«ä½ãã®ã¬ãã«ãããã£ã¦ãããè²ããªè¾²ä½ç©ãæçãã¤ãããããã«ãªã£ããã¦ã¼ã¶ãå¢ãããããä½ããã®ã¢ã¯ã·ã§ã³ãããå¾ã®åå¿ãã¡ãã£ã¨ã«ã¶ããªã£ã¦ãããæ¯æ¥ã®ããã«ã¡ã³ããã¦ãã¦éç¨ã大å¤ããã ãªã¨æãã
ãéçãªãã®ãç©è³ãæ°è»½ã«å人éã§éããããã¨ããä»çµã¿ãWebmoneyãPaypalãAmazonã«ãããã©ãããããæ©è½ã¯SNSçãªãµã¼ãã¹ã«ãã£ãæ¹ããããã ãããªãã¨æããééç³»ã¯æ³å¾ãã¨ã¦ããã£ããã ãããã©ã
æ¨æ¥ã¯ECããã®ã·ã¹ãã ã©ã¤ããã³ã°ãã¼ã¯ã¨ããã¤ãã³ãããããé£ã³å
¥ãã§LTãããæ°åã¨ã³ã¸ãã¢ã«disããã¦çããã®ãè¾ããªã£ããECããã«ã¯æè¿ããããã¨ã¨ã³ã¸ãã¢ãå
¥ç¤¾ãã¦ãã¦ããã®ã§é¡ãè¦ãã¦ãããç®çã§çºè¡¨ãããã©ã
ãããã
å ã®å½¼æ¹ã«æ¶ãã¦ãéä¸ã§ã¬ãã«ã¢ãããã¦è© å±è ããå¼·ããªã£ãå ´åã¯ã©ããªãã®ã ããã
å
é±æ«ã¯ç©ãèªãç®ã«ä½ãã¯ãããã®ã§ä¸»ã«èªæ¸ãããã
並åã«èªãã¨ããçãªã®ãæã©ã£ãã§è¦ãæ°ãããã®ã§ã試ãã«6åã»ã©ã並åã«èªãã§ã¿ããããããããä¸ã
èªã¿ããããªãã¦ãã£ãã¿ã¼1ãããã¾ã§ããã©ã®æ¬ãèªããªãã£ãã®ã§æè¡æ¸ã«ã¯åããªãèªæ¸æ³ã ã¨æãã¾ããã
èªæ¸ä»¥å¤ã®æé㯠scala ã試ãã¦ãããã¾ã ä½ãä½ã£ã¦ããªããåæ¨è«ããã¾ãã¡ãªæ°ãããã
TSUTAYAã§åãã漫ç»ãæ¥ææ¥ã¾ã§ã«è¿ããªãããããªãã£ãã®ã ãã©ãè¿ãã®ãå¿ãã¦ããã20å1000åã§1é±éåããäºãåºæ¥ã¦æ¼«ç»å«è¶ã¨ããã¹ãã¨å§åçã«ã³ã¹ãããã©ã¼ãã³ã¹ãããç´ æµãµã¼ãã¹ãªãã ãã©ã以å3æ¥ããã延æ»ããã ãã§4000åè¿ãã®å»¶æ»æãæã£ãè¨æ¶ããããä»åã¯ããã延æ»æãåããã¦ãã¾ãã®ãæãã¦ã¾ã è¿ããªãã§ããã
ä»æ¥ã¯ã¡ãã£ã¨äºå®ããã£ã¦ã
ãããã
å ã®å½¼æ¹ã«ã¯ä½ãããã®ã ããï¼ããã©ã â¦(èªåã«æãããããªãã)
2ã¶æã¡ããåã«MySQLã®ä¸æè°ãªbugã«ééããã®ã§å ±åããã¦é ãã¾ãã
- MySQLã®ãã¼ã¸ã§ã³: 5.1.42-community-log
- OS: CentOS5 Final
- ç¾è±¡: order by PRIMARY_KEY desc limit N ã§è©²å½ããã¬ã³ã¼ããåå¾ã§ããªã
ã©ã®ãããªäºãèµ·ãããã¯ãhttp://stackoverflow.com/questions/2844699/mysql-order-by-and-limit-gives-wrong-resultããã³ããã
Works correctly: mysql> SELECT id, created_at FROM billing_invoices WHERE (billing_invoices.account_id = 5) ORDER BY id DESC ; +------+---------------------+ | id | created_at | +------+---------------------+ | 1336 | 2010-05-14 08:05:25 | | 1334 | 2010-05-06 08:05:25 | | 1331 | 2010-05-05 23:18:11 | +------+---------------------+ 3 rows in set (0.00 sec) WRONG result when limit added! Should be the first row, id - 1336 mysql> SELECT id, created_at FROM billing_invoices WHERE (billing_invoices.account_id = 5) ORDER BY id DESC limit 1; +------+---------------------+ | id | created_at | +------+---------------------+ | 1331 | 2010-05-05 23:18:11 | +------+---------------------+ 1 row in set (0.00 sec) Works correctly: mysql> SELECT id, created_at FROM billing_invoices WHERE (billing_invoices.account_id = 5) ORDER BY created_at DESC ; +------+---------------------+ | id | created_at | +------+---------------------+ | 1336 | 2010-05-14 08:05:25 | | 1334 | 2010-05-06 08:05:25 | | 1331 | 2010-05-05 23:18:11 | +------+---------------------+ 3 rows in set (0.01 sec) Works correctly with limit: mysql> SELECT id, created_at FROM billing_invoices WHERE (billing_invoices.account_id = 5) ORDER BY created_at DESC limit 1; +------+---------------------+ | id | created_at | +------+---------------------+ | 1336 | 2010-05-14 08:05:25 | +------+---------------------+ 1 row in set (0.01 sec) Additional info: explain SELECT id, created_at FROM billing_invoices WHERE (billing_invoices.account_id = 5) ORDER BY id DESC limit 1; +----+-------------+------------------+-------+--------------------------------------+--------------------------------------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+------------------+-------+--------------------------------------+--------------------------------------+---------+------+------+-------------+ | 1 | SIMPLE | billing_invoices | range | index_billing_invoices_on_account_id | index_billing_invoices_on_account_id | 4 | NULL | 3 | Using where | +----+-------------+------------------+-------+--------------------------------------+--------------------------------------+---------+------+------+-------------+
ORDER BY ã ããªãåé¡ãªãã LIMIT ãæå®ãã㨠type ã index ãã range ã«ããããªãããããã
対ç㯠force index ããã created_at ã« index ã¯ã£ã¦ãã㦠created_at ã§ã½ã¼ãããã°ããã¨æãã¾ãã
http://bugs.mysql.com/bug.php?id=37830 ãã¿ãã¨2008å¹´é ã« fix ããã®ã«ä»å¹´ã¾ã大復活ãéããã¿ãããªã®ã§MySQL5.1ç³»ã¤ãã£ã¦ã人ã¯æ³¨æããã»ããããã§ãããã
話ããããã¾ãããåã¯
ãããã