laravel where in 查询缓慢优化

  • 在使用where in 查询,in里面的字段很多的情况下,查询数据库是非常的缓慢
  • 在有些场景下需要进行导入批量的查询,这很难绕过wherein查询
  • 这种情况怎么优化
尝试:
  1. 转化成等值查询,循环查询,但是结果并不是很理想,拆分去查询反而性能更差
  2. 通过约束条件去限制查询时间等,发现有效果但是好像不是很明显,很容易超时
在原表中数据量庞大,进行数据查询异常的缓慢,这里改变一下查询方法。
我们人为将表变小,在小表里面进行where in查询
通过时间约束在大表里面查询存为小表,在在小表里面查询,相对快上许多,但是还是慢
【laravel where in 查询缓慢优化】根治之法远离where in查询
SELECT * FROM (SELECT hwid,from_unixtime(connect_time) as connect_time,from_unixtime(disconnect_time) as disconnect_time,disconnect_type FROM tb_logs_access WHERE connect_time>{$d1} and connect_time <{$d2}) as tt where hwid in ({$hwids}) ORDER BY hwid

    推荐阅读