MySQL: Index invalid when selecting by a random id

  Kiến thức lập trình

There’s a table:

`id` INT(10) NOT NULL AUTO_INCREMENT,
`status` TINYINT(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,

When I processing the flowing statement (There’s more than 1000 records in this table), a table scan is processed. Why primary key index does not work?

SELECT * FROM t_test WHERE id = FLOOR(1 + RAND() * 1000)

enter image description here
And sometimes there 2 different results, why would this happen?
enter image description here

index invalid when mysql select by random id and sometimes return tow different values

LEAVE A COMMENT