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. 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_id
2011 3 5
11. Covering Index
•
MySQL Covering Index - ( ∀ )o sasata299's blog
http://blog.livedoor.jp/sasata299/archives/51336006.html
•
Covering Index
→
2011 3 5
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. Primary Key
• id Primary Key
1
Primary Key
• id
• id Primary Key
(“WHERE user_id=10001” )
2011 3 5
14. auto_increment
•
ID
CREATE TABLE seq_history(
seq_id bigint unsigned not null
);
• auto_increment
MySQL5.1 DB
auto_increment
2011 3 5
15. Read Write
• Read(SELECT) DB
Write DB DB
• Write SELECT
• SELECT
• Read
Write
2011 3 5
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 Key
2011 3 5