在我们准备的表结构tb_item 中, 一共存储了 300 万记录;
A. 根据ID查询
select * from tb_item where id = 1999\G;
查询速度很快, 接近0s , 主要的原因是因为id为主键, 有索引;
2). 根据 title 进行精确查询
select * from tb_item where title = 'iphoneX 移动3G 32G941'\G;
查看SQL语句的执行计划 :
处理方案 , 针对title字段, 创建索引 :
create index idx_item_title on tb_item(title);
索引创建完成之后,再次进行查询 :
通过explain , 查看执行计划,执行SQL时使用了刚才创建的索引