Answer the question
In order to leave comments, you need to log in
mysql index selection logic?
I have a posts table with the following indexes:
PRIMARY id
UNIQUE post_url
UNIQUE fb_id
UNIQUE tw_id
UNIQUE yt_video_id
UNIQUE bit_id
UNIQUE ticketfly_event_id
UNIQUE entity_id, amazon_asin
UNIQUE itunes_collection_id, entity_id
UNIQUE soundcloud_id
UNIQUE event_id
UNIQUE media_id, entity_id
UNIQUE entity_id, festival_id
INDEX itunes_release_date
INDEX amazon_release_date
INDEX entity_id, post_type, is_duplicate, deleted
INDEX google_country
explain
select `bq_posts`.*
from bq_posts
where (`entity_id` in ('93', '146', '191', '909', '946', '1444', '1686', '2102', '2129', '2147', '2213', '2236', '2532', '2553', '2591', '3119', '3175', '3283', '4742', '4825', '4906', '5095', '5556' /*Еще несколько тысяч идентификаторов*/))
and `post_type` in ('facebook', 'twitter', 'youtube', 'vevo', 'itunes', 'amazon', 'soundcloud', 'bit', 'ticketfly', 'festival', 'event', 'media')
and `bq_posts`.`deleted` is null
and `bq_posts`.`is_duplicate` = '0'
limit 10 offset 0;
Answer the question
In order to leave comments, you need to log in
And it all started when moving from mysql 5.7 to percona server 5.7. Before the move, this request was instantaneous, but now it has begun to slow down.Sorry for the sarcasm, "but this is MySQL, what did you expect?". One of the features of this database is a rather "clumsy" query optimizer (if you can call it that), which can not always correctly determine which index should be used. Of course, the incorrect definition of the "optimal" index is a problem not only for MySQL, but also for other databases ... but, somehow, very weakly in MySQL (and its derivatives) they try to deal with this. Also exacerbating the problem is the fact that MySQL can only use 1 index per query + some other factors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question