通过程序往数据库插入 50w 数据
数据表:
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time_date` datetime NOT NULL,
`time_timestamp` timestamp NOT NULL DEFAULT
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`time_long` bigint(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `time_long` (`time_long`),
KEY `time_timestamp` (`time_timestamp`),
KEY `time_date` (`time_date`)
) ENGINE=InnoDB AUTO_INCREMENT=500003 DEFAULT
CHARSET=latin1
其中 time_long、time_timestamp、time_date 为同一时间的不同存储格式
实体类 users
/**
* @author hetiantian
* @date 2018/10/21
* */
@Builder
@Data
public class Users {
/**
* 自 增 唯 一 id
* */
private Long id;
/**
* date 类 型 的 时 间
* */
private Date timeDate;
/**
* timestamp 类 型 的 时 间
* */
private Timestamp timeTimestamp;
/**
* long 类 型 的 时 间
* */
private long timeLong;
}
dao 层接口
/**
* @author hetiantian
* @date 2018/10/21
* */
@Mapper
public interface UsersMapper {
@Insert("insert into users(time_date,
time_timestamp, time_long) value(#{timeDate},
#{timeTimestamp}, #{timeLong})")
@Options(useGeneratedKeys = true,keyProperty =
"id",keyColumn = "id")
int saveUsers(Users users);
}
测试类往数据库插入数据
public class UsersMapperTest extends BaseTest {
@Resource
private UsersMapper usersMapper;
@Test
public void test() {
for (int i = 0; i < 500000; i++) {
long time = System.currentTimeMillis();