有四张表联合查询
分别是:
mes_info(订单信息表)约10万条数据,其中字段比较多gametype(游戏目录表)四条数据source(订单来源表)四条数据user_info(用户信息表)一百条数据左右主要是根据条件查询订单信息表里的信息,游戏目录表、订单来源表、用户信息表里的数据都很少,这三个表的主键为订单信息表的外键。
现在写的查询语句是:select * from mes_info,gametype,source,user_info where user_info.uid=mes_info.mes_user and mes_info.mes_source=source.source_id and mes_info.mes_game=gametype.gametype_id
现在查询需要:1.938s
请求优化语句

解决方案 »

  1.   

    不要用*  改成你需要用的字段
    where条件都加上索引了嘛?
      

  2.   

    贴出 explain select ..
    show index from ..
    以供分析。
      

  3.   

    select * from mes_info,gametype,source,user_info where user_info.uid=mes_info.mes_user and mes_info.mes_source=source.source_id and mes_info.mes_game=gametype.gametype_id建议如下:
    1,*变成所需要的字段
    2,默认的 mes_info,gametype,source,user_info变成left join。
    3,explain看下,表关联是否都走了索引?
    4,每个表的数据记录有多少条,尽量用大表作为主表。
      

  4.   

    如果都有主外键相关联。。优化就不能只是语句写法或者索引了。连WHERE 条件都没有,除了加大JOIN 的BUFFER ,加大内存了。