SQL optimization - group by optimization

1.group by optimization

insert image description here

Group by profession and count the number

select profession,count(*) from tb_user group by profession;

insert image description here
The performance of using temporary tables is relatively low.
insert image description here
Execute sql after creating the index

create index idx_user_pro_age_sta on tb_user(profession,age,status);

insert image description here

The performance analysis of the joint index that does not satisfy the leftmost prefix rule when grouping
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/weixin_44860226/article/details/131868312