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
比如:
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