Select * from (select tmp.userid userid, tmp.username ,tmp.likescore+tmp.commentscore+tmp.sharescore+tmp.tagscore+tmp.userscore+tmp.lsharescore+tmp.friendscore as score from
(
SELECT u.userid, u.username,
(select 10*count(1) from b_likes l where l.userid = u.userid) likescore,
(select 15*count(1) from b_comments c where c.userid = u.userid) commentscore,
(select 25*count(1) from b_page_shares s where s.userid = u.userid ) sharescore ,
(select 20*count(1) from b_tags t where t.userid = u.userid ) tagscore,
(select count(1)*10 score from (
Select Distinct friendid,userid
from b_friends f ) a
where a.userid=u.userid ) friendscore,
(select 25*count(1) from b_shares ls where ls.userid = u.userid ) lsharescore,
(SELECT (100 * count(rightflag))
FROM `b_scores` s
WHERE rightflag='1'
and level_no!=''
and u.userid=s.userid) userscore
FROM `b_users_data` u) tmp) tmp2 where tmp2.score != 0
order by tmp2.score desc, tmp2.username asc limit 10;
The slow query log says it took 72 seconds and 12.7k rows were examined. Apart from id, no other columns are indexed in any table.