最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

辛星简译MySQL中的last_query_cost_MySQL

来源:懂视网 责编:小采 时间:2020-11-09 19:56:33
文档

辛星简译MySQL中的last_query_cost_MySQL

辛星简译MySQL中的last_query_cost_MySQL:我们都知道在MySQL中可以通过show status like 'last_query_cost' 来查看查上一个查询的代价,而且它是io_cost和cpu_cost的开销总和,它通常也是我们评价一个查询的执行效率的一个常用指标。 下面是一段英文解释: The total cost
推荐度:
导读辛星简译MySQL中的last_query_cost_MySQL:我们都知道在MySQL中可以通过show status like 'last_query_cost' 来查看查上一个查询的代价,而且它是io_cost和cpu_cost的开销总和,它通常也是我们评价一个查询的执行效率的一个常用指标。 下面是一段英文解释: The total cost

我们都知道在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)它对于比较我们的开销是非常有用的,特别是我们有好几种查询方式可选的时候。

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

辛星简译MySQL中的last_query_cost_MySQL

辛星简译MySQL中的last_query_cost_MySQL:我们都知道在MySQL中可以通过show status like 'last_query_cost' 来查看查上一个查询的代价,而且它是io_cost和cpu_cost的开销总和,它通常也是我们评价一个查询的执行效率的一个常用指标。 下面是一段英文解释: The total cost
推荐度:
标签: 中的 mysql query
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top