我有两张表都是三四百万条数据。
这两张表要做关联查询,一下是查询的sql,我限制在查询记录数是1000条,查询时间要用5分钟。大神有没有觉得什么地方需要优化的,两张表对topic_id都有建索引。
SELECT
            a.subject_id,
            a.topic_id,
            FROM_UNIXTIME(b.pub_time, '%Y-%m-%d') put_time,
            group_concat(b.content) content
        FROM
            info2topic a
        LEFT JOIN info b ON a.info_id = b.info_id
        WHERE 1=1 
 and a.info_id > 1808830        GROUP BY 
            a.topic_id,
            FROM_UNIXTIME(b.pub_time, '%Y-%m-%d')
 LIMIT 1000

解决方案 »

  1.   

    也对info2topic.info_id建了索引
      

  2.   

    info2topic 创建info_id,topic_id的索引,
    info表也需要创建info_id的索引,
      

  3.   

    info表主键就是info_id,没有必要建索引了吧
      

  4.   

    不大懂 mysql , 但是总觉得你这个 SQL 跑不通。a.subject_id,
                a.topic_id,GROUP BY 
                a.topic_id
      

  5.   

     mysql可以这么写的
      

  6.   

    explain 下, 看看解释