I am observing weird behaviour which I am trying to understand.
MySQL version: 5.7.33 I have the below query:
select * from a_table where time>='2022-05-10' and guid in (102,512,11,35,623,6,21,673);
a_table
has primary key on time,guid
and index on guid
The query I wrote above has very good performance and as per explain plan is using index condition; using where; using MRR
As I increase the number of value in my in
clause, the performance is impacted significantly.
After some dry runs, I was able to get a rough number. For less than ~14500 values the explain plan is same as above. For number of values higher than this, explain plan only uses where
and it takes forever to run my query.
In other words, for example, if I put 14,000 values in my in
clause, the explain plan has 14,000 rows as expected. However, if I put 15,000 values in my in
clause, the explain has 221200324 rows. I dont even have these many rows in my whole table.
I am trying to understand this behaviour and to know if there is any way to fix this.
Thank you