sql - MySQL Innodb fail to use index due to extremely wrong rows estimation -


i've innodb table, query on table looks below.

select * x now() between , b 

i've create composite index on (a,b), query returns around 4k rows, while total number of rows in table around 700k.

however, when explain of execution plan, found query did not use expected index. because estimated rows around 360k, extremely larger actual value.

i know many posts (such why rows returns "explain" not equal count()?) had explained, explain estimation. force index solution tricky , may bring potential performance risks in future.

is there way can make mysql more accurate estimation (the current 1 90 times larger)? thanks.

innodb keeps approximate row counts tables. explained in documentation of show table status:

  • rows

the number of rows. storage engines, such myisam, store exact count. other storage engines, such innodb, value approximation, , may vary actual value as 40 50%.

i don't think there's way make innodb keep accurate row counts, it's not how works.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -