关于MySQL的联合索引,覆盖索引一直蒙蒙哒,所以写点东西来熟悉一下
首先创建一个表orders,结构如下:
create table orders(
order_id int unsigned auto_increment,
order_status int not null,
total_price int unsigned,
settle_type int,
store_id int,
buyer_id int,
goods varchar(20),
create_time datetime default current_timestamp,
primary key(order_id)
);
然后我们创建一个存储过程,向这个表中插入一些数据:
drop procedure if exists load_orders;
delimiter //
create procedure load_orders(count int unsigned)
begin
declare status int default 0;
declare type int default 0;
declare store int default 133;
declare price int default 85;
declare buyer int default 1001;
declare goods varchar(20) ;
declare i int unsigned default 0;
SET goods= 'al';
while i<count DO
SET status=mod (status,77);
SET type=mod(type,

本文探讨了MySQL中的联合索引和覆盖索引,通过创建一个orders表并插入数据,展示了不同查询方式下,使用联合索引如何影响查询效率。在没有索引时,count操作需要进行全表扫描。添加联合索引后,count操作显著加快,特别是针对索引列。文中还提到了索引条件处理(ICP)的概念,说明索引在存储引擎层已经进行了过滤。
最低0.47元/天 解锁文章
885





