资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

orderby的时候select上的列导致的影响分析

create table t1 (
a1 bigint  not null primary key auto_increment,
c10 char(10),
c100 char(100),
c200 char(200),
c30 char(255),
c300 text
)

insert into t1 (c10,c100,c200,c30,c300)values ('a','a','a','a','a');

insert into t1 (c10,c100,c200,c30,c300) select lpad(c10,10,'1'),lpad(c100,100,'1'),lpad(c200,190,'a'),lpad(c30,250,'1'),lpad(c300,2000,'1') from t1;


root@localhost [test]>select count(a1) from t1;
+-----------+
| count(a1) |
+-----------+
|     65536 |

select SQL_NO_CACHE count(1) from (
       select a1 from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a;


select SQL_NO_CACHE count(1) from (
       select a1,c100 from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a;

select SQL_NO_CACHE count(1) from (
       select a1,c100,c200 from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a;
   
   
select SQL_NO_CACHE count(1) from (
       select a1,c100,c200,c30 from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a; 

select SQL_NO_CACHE count(1) from (
       select a1,c100,c200,c30 ,c300 from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a;    

select SQL_NO_CACHE count(1) from (
       select * from t1 IGNORE INDEX (primary)   order by c10 desc  limit  1000 ) a;
   
   

做网站、网站建设过程中,需要针对客户的行业特点、产品特性、目标受众和市场情况进行定位分析,以确定网站的风格、色彩、版式、交互等方面的设计方向。创新互联还需要根据客户的需求进行功能模块的开发和设计,包括内容管理、前台展示、用户权限管理、数据统计和安全保护等功能。

order by 的时候 select 上的列导致的影响 分析





从上面的实验 结果都是只执行了 一遍 要是取得相对准确值 可以 多执行几次 

但我们 可以从最上面和 最后一条 可以看出 一个在 3.* 秒 一个在6.* 秒

说明 有排序的时候 影响 性能 的 不仅仅是 order by 后面的列 因为 都使用了 tmp 表 而加入tmp表的内容是select 当中 列 然后根据 order by 当中的 列 进行 排序 所以用的tmp 值是select col 的和 * rows  

大家也可以从 show profile 中 发现  Creating sort index  是上面的 执行性能 重点 进一步论证了 上面的观点
 
不足的地方 望大家 指正

当前名称:orderby的时候select上的列导致的影响分析
地址分享:http://cdkjz.cn/article/pcchoo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220