linux mysql5.6 优化_MySQL 5.6 查询优化器改进

本文详细介绍了MySQL的ICP(Index Condition Pushdown)优化策略,它适用于二级索引,能提高查询效率。同时,从MySQL 5.6.2版本开始,对于`ORDER BY ... LIMIT ...`的查询进行了优化,通过使用优先级队列方法来减少磁盘I/O。文章还提及了Ubuntu 14.04 LTS下安装LNMP(Nginx、PHP、MySQL)的教程链接。
摘要由CSDN通过智能技术生成

一.ICP

注意一下ICP的使用条件:

只能用于二级索引(secondary index)。

explain显示的执行计划中type值(join 类型)为range、 ref、 eq_ref或者ref_or_null。且查询需要访问表的整行数据,即不能直接通过二级索引的元组数据获得查询结果(索引覆盖)。

ICP可以用于MyISAM和InnnoDB存储引擎,不支持分区表(5.7将会解决这个问题)。

二.order by ..  limit ...优化

from MySQL 5.6.2 开始对order by ..  limit ...优化:

select col1,col2 from tx order by no_key_col limit offset,rowcount;

From 5.6.2 by treating the sort buffer as a priority queue:

Scan the table, inserting the select list columns from each selected row in sorted order in the queue. If the queue is full, bump out the last row in the sort order.

Return the first N rows from the queue. (If M was specified, skip the first M rows and return the next N rows.)

Before 5.6.2,Previously, the server performed this operation by using a merge file for the sort:

Scan the table, repeating these steps through the end of the table:

Select rows until the sort buffer is filled.

Write the first N rows in the buffer (M+N rows if M was specified) to a merge file.

Sort the merge file and return the first N rows. (If M was specified, skip the first M rows and return the next N rows.)

The cost of the table scan is the same for the queue and merge-file methods, so the optimizer chooses between methods based on other costs:

The queue method involves more CPU for inserting rows into the queue in order

The merge-file method has I/O costs to write and read the file and CPU cost to sort it

算法:

5.6使用queue:

把select 的列放入队列里,当队列满了把队列最后的出队列,就是把最大的、次大的、.....依次推到队列的前面,表所有行的列全部放完后,把第一个前rowcount 出队列,依次进行,都在sort buffer 里排序。

5.6之前:使用merge file

把row insert 到 sort buffer,sort buffer相当于一个堆栈,sort buffer被插满了,依次把当前堆栈里前面的rowcount出队列放入到merge file,直到所有的排好序,然后通过merge file 再排序取出结果。

--------------------------------------分割线 --------------------------------------

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL http://www.linuxidc.com/Linux/2014-05/102351.htm

--------------------------------------分割线 --------------------------------------

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值