Hi, I currently have the following two tables
devices which many columns but the one parameter being used in the where clause is imei. This column is set to unique().
device_logs which has other fields but the parameter being used in the where clause is device_imei.
Currently I have around 50 entries in the devices table and ~128,000 entries in the device_logs table. Average execution time for a query like the below is around 150ms which becomes very significant for 50 devices.
$lastLog = $this->hasMany('App\Models\DeviceLog', 'device_imei', 'imei')->orderBy('happened_at','desc')
->where('event_id', 16)->first();
What should I be looking at to improve the execution time? Should I index the device_imei in device_logs perhaps? Executing the same raw SQL query in phpmyadmin takes a similar time of 150ms.
Thanks!