MySQL secondary index of timestamp type misses data

59 Views Asked by At

Mysql version is 5.1.46. And the table looks like

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `createTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
 
  PRIMARY KEY (`id`),
  KEY `index_createTime` (`createTime`)
) ENGINE=InnoDB;

This query do works, it finds the data normally

select * from user where (createTime>='2022-04-25 16:11:48') and (createTime<='2022-04-25 16:11:49');

But this query not, it returns a empty result.

select * from user where (createTime>='2022-04-25 16:11:48.0') and (createTime<='2022-04-25 16:11:49.0');

I explain them, and found that only the values of rows are different, the rows value of the second sql is 1.

I noticed that mysql 5.1 does not support fraction. This may be the reason why the range query fails. But when I try this query,

select * from user where createTime='2022-04-25 16:11:48.0';

it works normally. That's weird. It feels like the secondary index has a problem with the range query of timestamp

By the way, Mysql 8.0 does not have this problem.

0

There are 0 best solutions below