首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL选择不同的非常慢

MySQL选择不同的非常慢
EN

Stack Overflow用户
提问于 2015-03-16 06:14:08
回答 2查看 496关注 0票数 1

对于我的移动应用程序,我使用一个web服务从MySQL数据库获取图像和所有记录,就像Instagram一样。

但是选择DISTINCT,采取超过7-8 seconds.is,有什么我可以做的事情,以减少时间?

代码语言:javascript
复制
SELECT distinct count(*) as totalrecord ,p.description,p.photo_id ,p.user_id,p.imagepath1 ,p.friends, p.is_report_photo,
    p.imagepath2,p.imagepath3,p.imagepath4,p.imagepath5,p.count_comment,p.count_like,p.created as photo_created ,

    (select username from users where id = p.user_id) as username , 
    (select country from users where id = p.user_id) as country, 
    (select email from users where id = p.user_id) as email , 
    (select image_path from users where id = p.user_id) as image_path ,
    (select gender from users where id = p.user_id) as gender, 
    (select privacy from users where id = p.user_id) as privacy,
    (select audio_privacy from users where id = p.user_id) as audio_privacy,
    (select video_privacy from users where id = p.user_id) as video_privacy,
    (select photo_privacy from users where id = p.user_id) as photo_privacy,

    If(pl.user_id && pl.photo_id !='',like_status,0) as islike ,
    If(pr.user_id && pr.photo_id !='',1,0) as isreport,
    p.user_visibility

    from friends as fr
    inner join users as u on u.id = (select distinct if (fr.user_id != $user_id,fr.user_id,(fr.to_user_id)) as rd
    from friends) && fr.read_status = '1'
    inner join photos as p on (p.user_visibility = 'p')
    LEFT JOIN photolike as pl ON pl.photo_id = p.photo_id && pl.user_id = $user_id
    LEFT JOIN photo_report as pr on pl. photo_id = pr.photo_id && pr.user_id = $user_id     
    ORDER BY p.photo_id DESC;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-16 06:41:14

使用减少时间的mysql索引

票数 1
EN

Stack Overflow用户

发布于 2015-03-16 06:21:10

代码语言:javascript
复制
Try using group-by clause instead of distinct.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29070595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档