After turning on log_queries_not_using_indexes
, I noticed that one query was rapidly filling up the slow query log:
SELECT abc.* FROM abc
WHERE abc.id
NOT IN (
SELECT DISTINCT abc_id FROM zyx
WHERE id = 12345
);
abc
is very small, just 3 rows of data. zyx
is relatively large with over 100,000 rows of data.
abc.id
has an index, but when I EXPLAIN
the query, the index isn't listed under either key
nor possible_keys
. This explains why the query is showing in the slow log, but my question is, why isn't it using the index?
In short, I have two questions:
- Do very small tables ignore indexes? I could see why, it doesn't save much time to use an index on 3 rows of data.
- If so, how can I prevent this query from flooding my slow query log?
Thank you for your time! :)
Additional information, if needed:
I have run ANALYZE TABLE abc
as I've read sometimes fixes the issue. I have also restarted MariaDB since adding the index.
More of the EXPLAIN
: select_type=PRIMARY, table=abc, type=ALL, possible_keys=NULL, key=NULL, key_len=NULL, ref=NULL, rows=3, Extra=Using where