MySQL 解释更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11351804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:04:18  来源:igfitidea点击:

MySQL EXPLAIN UPDATE

mysqlsqldatabasequery-optimization

提问by jim

I am trying to answer the following question as part of my college revision:

我正在尝试回答以下问题作为我大学修订的一部分:

Create an index on at least one attribute of a table in the ‘employees' database, where you use the MySQL ‘EXPLAIN' tool to clearly show the benefit (in terms or retreival) and the negative (in terms of update) of the creation of the index in question.

在'employees' 数据库中的表的至少一个属性上创建一个索引,您可以在其中使用 MySQL 'EXPLAIN' 工具清楚地显示创建的好处(在术语或检索方面)和负面(在更新方面)有问题的索引。

For the first part I have created an index on the employeestable and used the following query before and after the index to prove it's beneficial from a retrieval perspective:

对于第一部分,我在员工表上创建了一个索引,并在索引前后使用以下查询来证明从检索的角度来看它是有益的:

EXPLAIN SELECT * FROM employees WHERE birth_date = '1953-09-02';

This index had the effect of reducing the accessed rows from 300,000 to just 63.

该索引的作用是将访问的行从 300,000 减少到仅 63。

Now, i'm stumped on how to do the second part. I expected to be able to use the EXPLAINcommand with UPDATEbut it doesn't work for that.

现在,我对如何做第二部分感到困惑。我希望能够在UPDATE 中使用EXPLAIN命令,但它不起作用。

The UPDATEquery i'm trying to analyse is as follows:

我试图分析的UPDATE查询如下:

UPDATE employee SET first_name = 'first_name' WHERE birth_date = '1953-09-02';

Is this a suitable query to answer the question and how do I go about analysing.

这是一个合适的查询来回答这个问题以及我如何进行分析。

Many thanks in advance.

提前谢谢了。

回答by Raymond Tau

EXPLAIN UPDATEexists in MySQL 5.6but not MySQL 5.5by comparing the document of MySQL. Did you try that on MySQL 5.6 server?

EXPLAIN UPDATE通过比较MySQL的文档,在MySQL 5.6中存在但在MySQL 5.5中不存在。您是否在 MySQL 5.6 服务器上尝试过?

回答by andy

The reference doc of Mysql 5.6:http://dev.mysql.com/doc/refman/5.6/en/explain.html

Mysql 5.6 参考文档:http: //dev.mysql.com/doc/refman/5.6/en/explain.html

As of MySQL 5.6.3, permitted explainable statements for EXPLAIN are SELECT, DELETE, INSERT, REPLACE, and UPDATE. Before MySQL 5.6.3, SELECT is the only explainable statement.

从 MySQL 5.6.3 开始,允许的 EXPLAIN 可解释语句是 SELECT、DELETE、INSERT、REPLACE 和 UPDATE。在 MySQL 5.6.3 之前,SELECT 是唯一可解释的语句。