MySQL的联合索引和覆盖索引

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于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,
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值