last_query_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.
(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
last_query_cost的更多相关文章
- Mysql命令show global status求根溯源
近来,发现好多公司对mysql的性能监控是通过show global status实现的,因此对于这个命令想要探究一番,看他是否是实时更新的. 在此之前,我们必须搞明白mysql对于这个命令的执行过程 ...
- mysql 查询成本
SELECT SQL_NO_CACHE spu from dp_distributor_products_1_online where dpId > 15 AND dpId <= 60; ...
- MySQL运行状态show status详解
状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...
- MySQL运行状态show status中文详解(转)
要查看MySQL运行状态,要优化MySQL运行效率都少不了要运行show status查看各种状态,下面是参考官方文档及网上资料整理出来的中文详细解释: 状态名 作用域 详细解释 Aborted_cl ...
- 高性能MySQL笔记 第6章 查询性能优化
6.1 为什么查询速度会慢 查询的生命周期大致可按照顺序来看:从客户端,到服务器,然后在服务器上进行解析,生成执行计划,执行,并返回结果给客户端.其中“执行”可以认为是整个生命周期中最重要的阶段. ...
- MySQL如何关联查询
总的来说,mysql认为任何一个查询都是一次关联,并不仅仅是一个查询需要用到两个表匹配才叫关联,所以,在mysql中,每一个查询,每一个片段(包括子查询,甚至单表select)都可能是关联.所以,理解 ...
- mysql:键缓存
myisam的主要优化参数: key_buffer_size - 这对MyISAM表来说非常重要,是用来设置整个MySQL中常规Key Cache的大小.一般来说,如果MySQL运行在32位平台,此值 ...
- mysql show processlist命令 详解
SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...
- MySQL查询优化 (一)
以下的文章主要讲述的是MySQL查询优化的5个十分好用方法,熟悉SQL语句的人都清楚,如果要对一个任务进行操作的话,SQL语句可以有很多种相关写法,但是不同的写法查询的性能可能会有天壤之别. 本文列举 ...
随机推荐
- chromedriver各个版本的下载
驱动的下载地址如下: http://chromedriver.storage.googleapis.com/index.html 注意:64位向下兼容,直接下载32位的就可以啦,亲测可用.
- python函数(2017-8-2)
1. def 函数名(形式参数) 函数体 return "123" 函数执行了return之后就不再执行下面的代码 2. 默认形参实参的位置一一对应 如果要调整位置,指定形参名字 ...
- 人人都会设计模式:观察者模式--Observer
https://segmentfault.com/a/1190000012295887 观察者模式是抽像通知者和观察者,达到具体通知者跟具体观察者没有偶合.能达到不管是切换通知者,或者是切换观察者,都 ...
- linux文件IO操作篇 (二) 缓冲文件
2. 缓冲文件操作 //规模较大 实时性低的文件 //当数据长度快要超过缓冲区的范围时,或者时间周期达到时,数据才被送往指定位置 //需要使用FILE * 作为文件标识符 //stdin 标准输入 / ...
- C# 测量程序运行时间
using System.Diagnostics; Stopwatch watch = new Stopwatch(); watch.Start(); /* 需要测量运行时间的程序 */ watch. ...
- JAVA反射之 Field (属性)
主要方法: public static void main(String[] args) throws Exception { Class<?> clazz = Class.forName ...
- mysql 5.8 查询最新一条数据
SELECT * FROM ( ,) FROM (SELECT * FROM or_task_node ORDER BY created_date DESC) temp ) AS vars ) t g ...
- python2.7入门---循环语句(while)
接下来就要了解循环语句了.我们都知道,程序在一般情况下是按顺序执行的.编程语言提供了各种控制结构,允许更复杂的执行路径.循环语句允许我们执行一个语句或语句组多次,下面是在大多数编程语言中的循环 ...
- Java8新特性(一)——Lambda表达式与函数式接口
一.Java8新特性概述 1.Lambda 表达式 2. 函数式接口 3. 方法引用与构造器引用 4. Stream API 5. 接口中的默认方法与静态方法 6. 新时间日期 API 7. 其他新特 ...
- 13 IO多路复用 (未完成)
IO多路复用 6.select版-TCP服务器:最多1024 import select import socket import sys server = socket.socket(socket. ...