Answer the question
In order to leave comments, you need to log in
Very long query execution time (4903 sec - 81 min), what's wrong?
Good afternoon, I noticed that in production, the request takes about 2 seconds.
The site is powered by laravel and the query is executed using built-in syntax.
DB::table('wheels')
->select(DB::raw('count(DISTINCT models.id) as models_count, wheels.pcd, wheels.lz'))
->leftJoin('vehicles','vehicles.id','=','wheels.vehicle_id')
->leftJoin('modifications','modifications.id','=','vehicles.modification_id')
->leftJoin('models','models.id','=','modifications.model_id')
->groupBy('wheels.pcd','wheels.lz')
->orderBy('models_count','DESC')
->get();
select count(DISTINCT models.id) as models_count, wheels.pcd, wheels.lz
from `wheels`
left join `vehicles` on `vehicles`.`id` = `wheels`.`vehicle_id`
left join `modifications` on `modifications`.`id` = `vehicles`.`modification_id`
left join `models` on `models`.`id` = `modifications`.`model_id`
group by `wheels`.`pcd`, `wheels`.`lz`
order by `models_count` desc
Answer the question
In order to leave comments, you need to log in
there is no schema in the normal form, no query plan.
but the picture shows the absence of a key on vehicles.id
if this table does not really have a primary key, then because of this it definitely slows down.
RTFM https://dev.mysql.com/doc/refman/5.7/en/explain.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question