Re: Slow Query, Optimization Advice Needed
Hi,
AFAICT, the join order is the best you can get. However, one problem with MySQL 5.5 is that it re-computes statistics on every server restart. Hence, the query plan might not be stable. If you upgrade to MySQL 5.6, you will get persistent statistics that might give more predictable query plans.
Not sure how much it will give you, but you can consider creating some multi-column indexes for the non-unique index look-ups (aka ref access) in order to make the index cover all necessary columns. That way, the query will only need to access the index and not the actual table. Candidates are:
tblTrailerLogs(nMovementOutID, nTrailerID)
tblMovements(nTrailerID, tsMovement, nLocationID)
Øystein Grøvlen,
Senior Principal Software Engineer,
MySQL Group, Oracle,
Trondheim, Norway