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如何写
运行以上语句 直接当机 我尝试着把or去掉只剩下一个国家 可是这样不适合我的程序 必须要这样 怎么修改提高效率 如何join或者union如何写
解决方案 »
- 使用Mysql Workbench过程中的疑惑
- mysql 5.5 无法远程链接 root用户 host已经改为%
- MySql与sqlite的优缺点点对比!
- 数据插入不到数据库
- 没有怎么用过MySQL,存储过程这样写有问题吗?
- mysql5 中一个数据表可以储存多少条数据量
- mysql数据库,直接用复制的数据库文件夹放在data下,控制台能访问数据并且存在,但是php页面却是空白。
- mysql语句执行效率的优化问题
- 大家知不知道,在Mysql 一个数据库能放多少表 ,200个表有问题吗?性能会怎样。??
- 求mysql网络数据库开发案例或者教程
- mysql数据库进程列表中Command有10几个sleep 正常吗
- 帮忙写条查询语句
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 ;以供分析。
貌似我是没有建立过搜索的 因为我的数据库需要每天更新的
+--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| 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 | |
+--------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| 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 |
+----+-------------+-------+------+---------------+------+---------+------+-------+--------------------------------+
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 多好!
求解释
1.多了个and a.id=b.mid and a.id=b.mid看到了 这个去掉了 应该效率差不多
2.对了用in和用or效率差距大吗 ?
3.还有默认设置个字符串和默认是null 区别大吗?
还有一个问题就是我想用效率高点的其他组合语句 比如left join 或者union会提高吗效率 或者其他更高效的办法