select * from lib a,buchong b where a.country = '美国' or a.country = '法国' or a.country = '苏联' or a.country = '加拿大' or a.country = '葡萄牙' or a.country = '欧美' or a.country = '意大利' or a.country = '德国' or a.country = '西班牙' or a.country = '墨西哥' or a.country = '瑞典' or a.country = '俄罗斯' or a.country = '丹麦' or a.country = '波兰' or a.country = '英国' or a.country = '英语' or a.country = '马来西亚' and a.type = '动作' and a.palydate >= '2013-01-01 00:00:00' and a.palydate < '2014-01-01 00:00:00' and a.id=b.mid and a.id=b.mid and (a.positives is not null or a.prevues is not null or b.xxx is not null or b.yyy is not null)
运行以上语句 直接当机  我尝试着把or去掉只剩下一个国家 可是这样不适合我的程序 必须要这样 怎么修改提高效率 如何join或者union如何写   

解决方案 »

  1.   

    哪里宕机  mysql服务  操作系统 还是程序
      

  2.   

    系统当机 应该算很卡把  mysql服务应该还是在的 就是服务吃内存吧
      

  3.   

    贴出 
    explain select * from lib a,buchong b where a.country = '美国' or a.country = '法国' or a.country = '苏联' or a.country = '加拿大' or a.country = '葡萄牙' or a.country = '欧美' or a.country = '意大利' or a.country = '德国' or a.country = '西班牙' or a.country = '墨西哥' or a.country = '瑞典' or a.country = '俄罗斯' or a.country = '丹麦' or a.country = '波兰' or a.country = '英国' or a.country = '英语' or a.country = '马来西亚' and a.type = '动作' and a.palydate >= '2013-01-01 00:00:00' and a.palydate < '2014-01-01 00:00:00' and a.id=b.mid and a.id=b.mid and (a.positives is not null or a.prevues is not null or b.xxx is not null or b.yyy is not null);show index from lib ;
    show index from buchong ;以供分析。
      

  4.   


    貌似我是没有建立过搜索的 因为我的数据库需要每天更新的
    +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
    | Table        | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
    +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
    | lib |          0 | PRIMARY  |            1 | id          | A         |       39661 | NULL     | NULL   |      | BTREE      |         |
    +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------++--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
    | Table        | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
    +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
    | lib |          0 | PRIMARY  |            1 | id          | A         | NULL        | NULL     | NULL   |      | BTREE      |         |
    | buchong |          0 | PRIMARY  |            2 | mid         | A         |       39662 | NULL     | NULL   |      | BTREE      |         |
    +--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
      

  5.   

    +----+-------------+-------+------+---------------+------+---------+------+-------+--------------------------------+
    | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows  | Extra                          |
    +----+-------------+-------+------+---------------+------+---------+------+-------+--------------------------------+
    |  1 | SIMPLE      | b     | ALL  | NULL          | NULL | NULL    | NULL | 39662 |                                |
    |  1 | SIMPLE      | a     | ALL  | PRIMARY       | NULL | NULL    | NULL | 39661 | Using where; Using join buffer |
    +----+-------------+-------+------+---------------+------+---------+------+-------+--------------------------------+
      

  6.   

    至少 先把  那么多的国家的  or  条件 替换了吧!写在程序里面 难到不是 很长  很繁琐
    a.country  in ('美国','意大利'......)
    这一段
    and a.palydate >= '2013-01-01 00:00:00' and a.palydate < '2014-01-01 00:00:00' and a.id=b.mid and a.id=b.mid and (a.positives is not null or a.prevues is not null or b.xxx is not null or b.yyy is not null)
    and a.palydate < '2014-01-01 00:00:00' 可以去掉吧!
    and a.id=b.mid and a.id=b.mid  条件重复了吧!
    (a.positives is not null or a.prevues is not null or b.xxx is not null or b.yyy is not null)你直接  设计表的 时候  给个 默认default  多好!  
    求解释 
      

  7.   

    嗯谢谢 我还要问一下问题
    1.多了个and a.id=b.mid and a.id=b.mid看到了 这个去掉了  应该效率差不多
    2.对了用in和用or效率差距大吗 ?
    3.还有默认设置个字符串和默认是null 区别大吗?
    还有一个问题就是我想用效率高点的其他组合语句 比如left join 或者union会提高吗效率 或者其他更高效的办法