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.

(last_query_cost对于简单的查询可以精确的得到计算,但于包含子查询或union的复杂查询值是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.

There's some interesting resources on the query optimizer available online, if you want to learn more. Unfortunately, I don't have any links for you readily available, but it shouldn't be too hard to find some resources through a simple search for "mysql query optimizer".

参考:

https://dev.mysql.com/doc/refman/5.5/en/server-status-variables.html#statvar_Last_query_cost
http://stackoverflow.com/questions/1071708/further-information-about-last-query-cost-in-mysql

最新文章

  1. ABySS非root权限安装
  2. html中meta的设置
  3. Molile App(HTTP/HTML)—Record and Analyze Traffic
  4. MySQL Python教程(4)
  5. class.forname()用法 转
  6. java 接口学习
  7. python数字图像处理(5):图像的绘制
  8. 版本引发的血案check the manual that corresponds to your MySQL server version for the right syntax
  9. P92认识对话框
  10. 1085. Perfect Sequence (25)
  11. 常用JS验证和函数
  12. Javascript--dataTransfer
  13. 关于zepto在chrome中触发两次的解决方案
  14. 【原创】java NIO FileChannel 学习笔记 FileChannel实现分析 即FileChannelImpl分析
  15. Codeforces Round #539 Div. 1
  16. 【BZOJ4712】洪水
  17. DevExpress WinForms使用教程:WinForms Fluent Design和Acrylic Effects
  18. jquery中ajax的dataType的各种属性含义
  19. [原创] rtrim() 格式化中文问题
  20. JavaScript中函数的变量提升问题

热门文章

  1. Python学习笔记:第一天python基础
  2. vuls安装记录
  3. 基于jQuery的2048小游戏设计(网页版)
  4. 使用 MySQL 存储 Hue 元数据
  5. linux里面的fork函数创建一个新进程
  6. javac一次性编译多个包下的.java文件
  7. 【个人训练】(POJ3279)Fliptile
  8. Django源码分析之server
  9. Bellman_ford标准算法
  10. [C/C++] new/delete和malloc/free基本区别