社内勉強会:ソーシャルゲームのデータベース設計入門

4,792 views
4,805 views

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,792
On SlideShare
0
From Embeds
0
Number of Embeds
1,344
Actions
Shares
0
Downloads
47
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

社内勉強会:ソーシャルゲームのデータベース設計入門

  1. 1. 2011 3 42011 3 5
  2. 2. • DB • Index Index Covering Index Primary Key Read Write • MySQL DB SQL2011 3 5
  3. 3. • →(10001,A) ※ • Primary Key →Primary Key • Primary Key2011 3 5
  4. 4. • ID ID 1 1 2 2 22011 3 5
  5. 5. • ID ID 1 10001 1 10002 2 10001 ID ID 1 10001 2 10002 1 10002 2 10001 2 10002 ID 10001 100022011 3 5
  6. 6. • ID ID 1 101 2 102 ID ID 3 103 1 101 4 102 2 102 3 103 4 102 ID 101 102 1032011 3 5
  7. 7. ALTER TABLE • • (ALTER TABLE) →ALTER TABLE • • →2011 3 5
  8. 8. ID ID 1 1 101 1 1 2 234 2 1 3 553 3 1 4 232 4 2 1 102 2 2 271 2 3 952 ID 1 101 234 553 232 873 0 102 0 2 102 271 8652 98 0 234 202 0 3 103 952 76 765 872 45 0 0 4 102 197 2312 762 4 232 672 34 •2011 3 5
  9. 9. Index • WHERE Index Primary Key WHERE user_id = 10001 → user_id Index( Primary Key) WHERE user_id = 10001 AND friend_id = 10002 → (user_id, friend_id) WHERE visiting_id = 10001 AND visited_id IN (1,2,3) AND action=2 → (visiting_id,visited_id,action) WHERE status = 2 ORDER BY start_time → (status,start_time)2011 3 5
  10. 10. Index • Index WHERE start_time < 12345678 AND state = 2 →(start_time,state) (state,start_time) • Index WHERE visited_id = 10002 AND visiting_id = 10001 AND action=2 → (visiting_id,visited_id,action) • Index WHERE visiting_id = 10001 AND action = 2 AND visited_id = 10002 → (visiting_id,visited_id,action) Index visiting_id2011 3 5
  11. 11. Covering Index • MySQL Covering Index - ( ∀ )o sasata299s blog http://blog.livedoor.jp/sasata299/archives/51336006.html • Covering Index →2011 3 5
  12. 12. Primary Key id • Primary Key → Primary Key MySQL id Primary Key MySQL :: MySQL 5.1 :: 13.5.13 InnoDB http://dev.mysql.com/doc/refman/5.1/ja/innodb-table-and-index.html • id WHERE id IN (a,b,c,d...) • id id Primary Key ( Covering Index )2011 3 5
  13. 13. Primary Key • id Primary Key 1 Primary Key • id • id Primary Key (“WHERE user_id=10001” )2011 3 5
  14. 14. auto_increment • ID CREATE TABLE seq_history( seq_id bigint unsigned not null ); • auto_increment MySQL5.1 DB auto_increment2011 3 5
  15. 15. Read Write • Read(SELECT) DB Write DB DB • Write SELECT • SELECT • Read Write2011 3 5
  16. 16. • Read/Write SQL • IO → →2011 3 5
  17. 17. MySQL • DB DB DB DB DB (3)Relay Log (1) (INSERT,UPDATE ) SQL Binary Log SQL IO Binary Log Relay Log (2)IO Binary Log DB2011 3 5
  18. 18. DB • DB DB →MySQL 1 • → SSD cf.2011 3 5
  19. 19. • NG UPDATE history_tbl SET state = 2 WHERE state = 1 LIMIT 10 →state=1 UPDATE history_tbl SET state = 2 ORDER BY finish_time LIMIT 1 → finish_time • UPDATE WHERE Primary Key2011 3 5

×