mysql - When is JOIN executed in this case? -
let's select data table "posts":
id | bigint(20) | pk text | varchar(400)
and table "likes":
user_id | bigint(20) post_id | bigint(20)
those 2 fields joined primary key
let's select on table "posts" 500'000 records simply
select id, text posts limit 0,20
and need know posts have (there can 1 per user/post, see primary-key definition). do
select id, text posts left join likes on posts.id = likes.post_id limit 0,20
will query join on 20 records or on 500'000 of table "posts"? no column of "likes" used in where/group clause in effective query.
output of
explain select id posts left join likes on posts.id = likes.post_id limit 0 , 20 id select_type table type possible_keys key key_len ref rows 1 simple posts index null primary 16 null 58 using index 1 simple likes ref primary primary 8 legendaily.posts.id 1 using index
thanks
Comments
Post a Comment