2017-06-19 85 views
0

我在QOVENDOR表运行此命令。的理解输出EXPLAIN MySQL命令

EXPLAIN SELECT * 
FROM QOVENDOR 
WHERE V_NAME LIKE "B%" 
ORDER BY V_AREACODE 

QOVENDOR表:

CREATE TABLE `qovendor` (
    `V_CODE` int(11) NOT NULL, 
    `V_NAME` varchar(35) NOT NULL, 
    `V_CONTACT` varchar(15) NOT NULL, 
    `V_AREACODE` char(3) NOT NULL, 
    `V_PHONE` char(8) NOT NULL, 
    `V_STATE` char(2) NOT NULL, 
    `V_ORDER` char(1) NOT NULL, 
    PRIMARY KEY (`V_CODE`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 

我得到的输出是:

+------+-------------+----------+------+---------------+------+---------+------+------+-----------------------------+ 
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra      | 
+------+-------------+----------+------+---------------+------+---------+------+------+-----------------------------+ 
| 1 | SIMPLE  | QOVENDOR | ALL | NULL   | NULL | NULL | NULL | 15 | Using where; Using filesort | 
+------+-------------+----------+------+---------------+------+---------+------+------+-----------------------------+ 

这些信息应该帮助我建立更高效的查询,但我有一个很难理解如何。具有一些相关信息的唯一非空列是Extra,select_type,Type和Rows。我确实使用where子句,不知道Using filesort的意思,除了它与order by有关。如果这个查询效率最高,我该如何推断?

为了评价性能我应该有某种形式的CPU成本和时间数据(如Oracle DBMS与EXPLAIN命令提供)。

+0

你有一个小桌子(15行)和基本查询。这些都无法让你更有效率。如果你的表有一百万行,你就需要考虑索引V_NAME和V_AREACODE,这样当您运行查询的MySQL不必须扫描在整个百万行返回结果 – Tik

+0

如果你创建V_NAME指数将有可能以使用该索引,但我不确定mysql是否足够聪明。 – Adder

+0

这是因为您的设置中没有任何内容可以显示。尝试在查询WHERE子句中使用列V_CODE,您将获得更多信息。或者在V_NAME列上创建索引。在您当前的查询中没有要使用的索引,因此没有任何解释。 –

回答

0

在MySQL explain不会为你提供时间,也不能与CPU的成本信息。 MySQL documentation on explain描述输出每一列的确切含义:

Column   JSON Name  Meaning 
id    select_id  The SELECT identifier 
select_type None    The SELECT type 
table   table_name  The table for the output row 
partitions  partitions  The matching partitions 
type   access_type  The join type 
possible_keys possible_keys The possible indexes to choose 
key   key    The index actually chosen 
key_len  key_length  The length of the chosen key 
ref   ref    The columns compared to the index 
rows   rows    Estimate of rows to be examined 
filtered  filtered   Percentage of rows filtered by table condition 
Extra   None    Additional information 

从视图的查询优化点,大概的类型,possible_keys,钥匙,行和额外的字段是最重要的。他们的详细描述可以在链接的MySQL文档中找到。