现在有两个表,每个表的数据量 30万左右 。表一的id和表2的res_id是关联的,因为表2和另一张表关联,所以无法做外键。
现在需求是 检索条件都在表一,但是排序是根据表二的字段排序。普通写法最后结果,都在5S以上速度太慢。求大神给出优化意见。刚才没有补充,on后面都是主键,where后面的都建立了普通索引,orderby 后面的也是普通索引。
sql 如下:
SELECT
a.id,
a.title,
a.type,
a.digest,
a.file_type,
a.file_sufix,
a.bpackage,
a.author_name,
a.source,
a.source_name,
a.org_name,
b.download_count,
b.preview_count,
b.favorite_count,
a.author,
a.section_name,
a.subject_name,
a.version_name,
a.material_name,
a.chapter_name,
b.evaluate_count
FROM
res_resource a
LEFT JOIN res_statistics b
ON a.id = b.res_id
WHERE a.dflag = 0
AND a.sflag = 1
AND a.publish_status = '1'
ORDER BY overall_score DESC LIMIT 0,10