Covering index used despite missing column
8
votes
2
answers
395
views
I have the following query, using MariaDB 10 / InnoDB:
SELECT id, sender_id, receiver_id, thread_id, date_created, content
FROM user_message
WHERE thread_id = 12345
AND placeholder = FALSE
ORDER BY date_created DESC
LIMIT 20
This query fetches messages according to the given conditions and sorts by date created.
I have a covering index over
(thread_id, date_created)
.
When running EXPLAIN, the correct index is used and I get the output "Using where", although the query is using a column in the middle of the statement that is not in the index. I can use any value for "placeholder = x" and the result is the same.
If I change the sorting to use another column, the EXPLAIN correctly indicates "Using where. Using filesort."
I'm having a head-scratching moment. Could anyone please shed light on this? What I would expect to see is that an additional filesort would be needed as the covering index could not be completely used due to the additional column.
Asked by Tom
(205 rep)
Jun 17, 2019, 05:53 PM
Last activity: Jun 18, 2019, 08:31 AM
Last activity: Jun 18, 2019, 08:31 AM