mysql - optimize the query with multiple table -


i have query in data coming multiple tables.

select iuserid,        iuserid userid,        (case vusbg             when 1 'yes'             when 0 'no'         end) vusbg,        concat(vfirstname,' ',vlastname) name,        vemail,        etype,        estatus,        taddeddate,        eexpert,        eadmin,    (select count(iuserid) total    tbl_friend    iuserid = tbl_user.iuserid) count_f,    (select count(*)    bar_followers    bar_followers.iuserid = tbl_user.iuserid) bar_follows,    (select count(b.ibrandid)    tbl_company_follow,         tbl_brand b    tbl_company_follow.iuserid = tbl_user.iuserid      , b.icompanyid = tbl_company_follow.icompanyid) brand_follows,    (select sum(points) totalpoints    tbl_points,         tbl_post p    iuserid = tbl_user.iuserid      , p.ipostid = tbl_points.post_id) countpoints tbl_user 

this query took 8.3595 seconds

how can minimize time?

your query reasonable, except lack of explicit join syntax.

check sure have following indexes:

  • tbl_friend(iuserid)
  • bar_followers(iuserid)
  • tbl_company_follow(iuserid, icompanyid)
  • tbl_brand(icompanyid)
  • tbl_post(iuserid, ipostid)
  • tbl_points(post_id, points)

however, depending on size of data, 8-9 seconds might reasonable.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

python - RuntimeWarning: PyOS_InputHook is not available for interactive use of PyGTK -