I got a table with over 6.6 millions rows.
I got a field, named trip_id who’s in BINARY(16). I find my query too slow (0.2 seconds). This query run near once every 3 seconds.
Before doing anything stupid, I want to know if I lower the index size on trip_id from full to 12, would it make a difference ?
If I try to tweak my query more, would it make a difference ?
Thanks
EDIT:
Query :
SELECT stop_times.stop_id
FROM trips
LEFT JOIN stop_times ON trips.trip_id = stop_times.trip_id
WHERE trips.route_id = '141'
GROUP BY stop_times.stop_id
ORDER BY trips.trip_headsign ASC,
stop_times.stop_sequence ASC
trip_id BINARY(16)
route_id SMALLINT(3)
trip_headsign VARCHAR(50)
stop_sequence SMALLINT(3)
Explain of the query :

After doing researches, I’ve found the problem because yes, 0.2 seconds is slow.
First, instead of doing a
LEFT JOIN,JOINis faster here. But the important point, I was matching all results from trips in the WHERE statement.However, since a bus can only have 2 directions, I only have to limit my results to 2. Now, my results are near 0.018. Over 1000% improvement.