Forum Moderators: open
EXPLAIN SELECT count( * ) AS num_messages
FROM messages, users
WHERE messages.username = 'johndoe'
AND users.username = 'johndoe'
AND messages.sent_date >= users.last_activity
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE users ref username username 53 const 1 Using where
1 SIMPLE messages ref username username 53 const 195 Using where EXPLAIN SELECT count( * ) AS num_comments
FROM comments, users
WHERE users.username = 'johndoe'
AND comments.page = users.id
AND comments.sent_date >= users.last_activity id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE users ref PRIMARY,username username 53 const 1 Using where
1 SIMPLE comments ALL page NULL NULL NULL 52 Range checked for each record (index map: 0x2)
ALTER TABLE
users
ADD FOREIGN KEY
(comments_page)
REFERENCES comments(page)