您的位置:首页 > 数据库

sql查询效率

2016-06-22 16:06 267 查看
1.对于大数据量的查询不要使用or条件,应该使用union来替代(如果不需要排序或者去重可以使用union all

比如:

select * from a where name like ? or age = ?

转换后是

 select * from a where name like 

union

select * from a where  age = ?

2.批量插入

最快:SQL语句进行拼接,使用 insert into table () values (),(),(),()然后再一次性插入,

如果字符串太长,则需要配置下MYSQL,在mysql 命令行中运行 :set global max_allowed_packet = 2*1024*1024*10


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql 数据库