Код: Выделить всё
select * from `activities` where `device_id` = ? and `battery_level` is not null order by `created_at` desc limit 1
Моя таблица выглядит так:

И как я использую модели: (занимает 1500 мс)
Код: Выделить всё
Activity::query()
->where('device_id', 288)
->whereNotNull('battery_level')
->orderByDesc('created_at')
->first();
Код: Выделить всё
DB::table('activities')
->where('device_id', 288)
->whereNotNull('battery_level')
->orderByDesc('created_at')
->first();
Есть идеи, что я здесь делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/731 ... t-on-mysql