MySQL index

  1. 创建一个只有主键的表(无其他索引)
CREATE TABLE mgm_recommend_info(
    id bigint not null primary key auto_increment comment "ID",
    referee varchar(255) not null COMMENT "被推荐人(申请人)",
    bank varchar(255) not null COMMENT "银行",
    card_type tinyint not null COMMENT "卡类型",
    card_no   varchar(255)  COMMENT "卡号",
    recommender varchar(255) not null COMMENT "推荐人",
    application_id varchar(255) not null COMMENT "申请ID",
    time datetime not null COMMENT "时间",
    state tinyint not null COMMENT "状态",
    created_time datetime not null COMMENT "创建时间",
    updated_time timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='推荐信息表';

2.插入数据

insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('张三', '上海银行',1,'','李四','111111', '2018-04-01 10:00:00', 1, now());

insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('张三', '上海银行',1,'123456789','李四','111111', '2018-04-01 11:00:00', 2, now());

insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('张三', '上海银行',1,'123456789','李四','111111', '2018-04-01 12:00:00', 3, now());

insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('张三', '上海银行',1,'123456789','李四','111111', '2018-04-01 13:00:00', 4, now());

insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('王五', '上海银行',1,'','李四','111111', '2018-04-01 13:00:00', 1, now());
insert into mgm_recommend_info(referee, bank, card_type, card_no, recommender, application_id, time, state,created_time) values('王五', '上海银行',1,'223456789','李四','111111', '2018-04-01 13:00:00', 2, now());

3.time字段加索引
这里写图片描述

3.time, state字段各自加索引
这里写图片描述

  1. time,state先后加索引
    这里写图片描述

猜你喜欢

转载自blog.csdn.net/morning_china/article/details/79861829