我们都知道在MySQL中可以通过show  status  like  ‘last_query_cost‘  来查看查上一个查询的代价,而且它是io_cost和cpu_cost的开销总和,它通常也是我们评价一个查询的执行效率的一个常用指标。

下面是一段英文解释:

The total cost of the last compiled query as computed by the query optimizer. This is useful for comparing the cost of different query plans for the same query. The default value of

0 means that no query has been compiled yet. The default value is 0. Last_query_cost has session scope.

The Last_query_cost value can be computed accurately only for simple “flat” queries, not complex queries such as those with subqueries or UNION. For the latter, the value is set to 0.

Q:

When doing query optimization, the SHOW STATUS query returns values that are easy to understand with some practice and explanation.

But last_query_cost is obscure and poorly documented.

The only thing explained is that it must be read as an anti-macho value: the smaller the better.

But do we have further information about this high-level value? What is its unit? How is it calculated (estimated)? etc. How can we use it for an advanced profiling?

A:

This has to do with how the MySQL Query Optimizer works. When you enter and execute a query, MySQL will construct a query plan. This is done by evaluating how the query can be executed in several different ways, and assigning "costs" to the different possibilities.

These costs are based mostly on internal statistics, and includes data such as the number of rows in the table, the cardinality of different indices and so forth. When this is done, MySQL choses the least expensive plan and executes the query. The last_query_cost

value is this cost value.

As you‘ve no doubt seen in the manual:

The total cost of the last compiled query as computed by the query optimizer. This is useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet. The default value is 0. Last_query_cost

has session scope.

This is indeed true. The value is only useful as a quantitative measurement to compare different queries.

相信朋友们只要英语过了六级,甚至是四级都能看得懂,因此我这里只是提炼一下其中的要点,要点如下:

(1)它是作为比较各个查询之间的开销的一个依据。

(2)它只能检测比较简单的查询开销,对于包含子查询和union的查询是测试不出来的。

(3)当我们执行查询的时候,MySQL会自动生成一个执行计划,也就是query  plan,而且通常有很多种不同的实现方式,它会选择最低的那一个,而这个cost值就是开销最低的那一个。

(4)它对于比较我们的开销是非常有用的,特别是我们有好几种查询方式可选的时候。

原文:http://blog.csdn.net/xinguimeng/article/details/47833073

mysql+last_query_cost_辛星简译MySQL中的last_query_cost相关推荐

  1. mysql+last_query_cost_辛星简译MySQL中的last_query_cost_MySQL

    我们都知道在MySQL中可以通过show status like 'last_query_cost' 来查看查上一个查询的代价,而且它是io_cost和cpu_cost的开销总和,它通常也是我们评价一 ...

  2. 查看mysql数据插入时间_[译] MySQL 最佳实践 —— 高效插入数据

    Get the dolphin up to speed - Photo by JIMMY ZHANG on Unsplash[1] 当你需要在 MySQL 数据库中批量插入数百万条数据时,你就会意识到 ...

  3. 零积分下载,2014年辛星mysql教程秋季版第一本已经完工,期待您的支持

    经过一段时间的不懈努力.终于,2014年辛星mysql教程秋季版的第一本,即夯实基础已经完工,在csdn的下载地址为:去下载地址 ,假设左边地址跪了,能够去http://download.csdn.n ...

  4. mysql中leave和_MySQL数据库之Mysql存储过程使用LEAVE实现MSSQL存储过程中return语法

    本文主要向大家介绍了MySQL数据库之Mysql存储过程使用LEAVE实现MSSQL存储过程中return语法 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. DELIMITER ...

  5. mysql 只允许本地登陆 centos,Centos中MySQL设置密码跟不允许匿名登陆

    在Centos中刚安装完的Mysql,root用户默认是无密码的,并且允许匿名登录,当然仅限于本地登陆.这点我们可以通过查看数据库mysql中user表得到检验: 由user表可以看出,root用户对 ...

  6. 辛星php函数,辛星和您用更简略的方式去实现PHP中的验证码

    辛星和您用更简单的方式去实现PHP中的验证码 说实话,提到验证码我想大家都不会陌生,确实,验证码还是挺常见的,现在搜索一下PHP的验证码类简直是海量的数据,那我们今天就来实现一个自己的验证码把,不过它 ...

  7. mysql 添加int列_在MySQL中现有的int列的值中添加字符?

    要将字符添加到现有的int列值中,请使用MySQL CONCAT().让我们首先创建一个表-mysql> create table DemoTable ( Amount int ); 使用插入命 ...

  8. mysql数据库优化课程---15、mysql优化步骤(mysql中最常用最立竿见影的优化是什么)...

    mysql数据库优化课程---15.mysql优化步骤(mysql中最常用最立竿见影的优化是什么) 一.总结 一句话总结:索引优化最立竿见影 索引优化:不然有多少行要扫描多少次,1亿行大概是5到10分 ...

  9. mysql什么情况会加意向锁_MySQL中的锁4-插入意向锁和自增锁

    插入意向锁(Insert Intention Lock) 插入意向锁本质上可以看成是一个Gap Lock 普通的Gap Lock 不允许 在 (上一条记录,本记录) 范围内插入数据 插入意向锁Gap ...

最新文章

  1. java中的队列详解
  2. OPENCV计算图片间转换关系
  3. 防止用户利用PHP代码DOS造成用光网络带宽
  4. AI学会了用“人眼”看世界,甚至连人类瞳孔的细微缩放都能模拟 | 杜克大学...
  5. GitHub 私有仓库完全免费面向团队提供
  6. dojo Quick Start/dojo入门手册--面向对象,定义Class
  7. [leetcode] 144. 二叉树的前序遍历
  8. (转).gitignore详解
  9. bmp180气压传感器工作原理_各种传感器工作原理汇总
  10. SQL注入之错误注入_基于updatexml()
  11. java词频统计——web版支持
  12. flash与CPU连接及flash属性描述文件
  13. 复杂网络分析软件NetworkX和UCINET数据关联的方法
  14. PC微信逆向获取聊天表情
  15. 丹佛机场行李系统案例分析
  16. QT绘制不规则多边形
  17. unity获取电磁笔压感_电磁笔的分类和特性
  18. Hibernate:DisjunctionConjunction构造复杂的查询条件
  19. 【附源码】计算机毕业设计java兴发农家乐服务管理系统设计与实现
  20. 计算机发展史—从织布机到IBM!

热门文章

  1. FastReport数据库连接路径及软件的最终分发数据库路径问题
  2. 重庆理工大学图像处理实验三:图像分割
  3. zynq 和fpga区别_FPGA复位的正确打开方式
  4. linux如何运行java程序,Linux环境下运行简单java程序
  5. 表单多条相同name数据的获取
  6. 创建向导时为其添加path,指为jar添加到path里面
  7. SQL SERVER 事务例子
  8. 自定义RecyclerView.ItemDecoration,实现RecyclerView的分割线效果
  9. Qt Quick实现的疯狂算数游戏
  10. Mvc.Ext.Net项目架构(一)