- 在使用where in 查询,in里面的字段很多的情况下,查询数据库是非常的缓慢
- 在有些场景下需要进行导入批量的查询,这很难绕过wherein查询
- 这种情况怎么优化
- 转化成等值查询,循环查询,但是结果并不是很理想,拆分去查询反而性能更差
- 通过约束条件去限制查询时间等,发现有效果但是好像不是很明显,很容易超时
我们人为将表变小,在小表里面进行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
推荐阅读
- laravel 8 修改默认的paginate分页模板
- laravel|国际支付对接,信用卡支付对接,stripe的使用
- laravel|laravel执行过程
- 搭建远程GIT
- Laravel 自带的Auth验证登录
- php|lnmp搭建遇到的尴尬事(一)
- Laravel mysql 添加外键失败
- php|laravel attempt登陆认证时候帐号密码输入正确但返回false的情况
- Laravel|laravel 验证大于零的数字
- laravel|Composer 本地路径加载 laravel-admin 扩展包