mysql explain结果_了解MySQL中EXPLAIN的结果

我有两个具有相同输出的独立查询.现在我想了解哪一个更好?

查询1:

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

|----|-------------|-------|------|---------------|--------|---------|--------|------|----------------------------------------------------|

| 1 | SIMPLE | t1 | ALL | (null) | (null) | (null) | (null) | 9 | Using where |

| 1 | SIMPLE | t2 | ALL | (null) | (null) | (null) | (null) | 9 | Using where; Using join buffer (Block Nested Loop) |

QUERY2:

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

|----|--------------------|-------|------|---------------|--------|---------|--------|------|-------------|

| 1 | PRIMARY | t1 | ALL | (null) | (null) | (null) | (null) | 9 | Using where |

| 2 | DEPENDENT SUBQUERY | t2 | ALL | (null) | (null) | (null) | (null) | 9 | Using where |

那么哪一个更好,为什么?

我读了大约EXPLAIN here,但我还不知道哪个参数很重要?或者哪个参数显示我这样的列需要索引,或者我的查询需要优化?

在上面的两个解释结果中,除了:select_type和extra之外,所有列都是相同的.那么哪一个更好:

>

>简单,简单

>主要的,相关的子信息

>

>使用where,使用where;使用连接缓冲区(块嵌套循环)

>使用where,使用where

编辑:这是两个查询:

查询1:

SELECT t2.color FROM mytable t1

JOIN mytable t2 ON t1.related = t2.id

WHERE t1.id = '4'

QUERY2:

SELECT t1.color FROM mytable t1

WHERE exists (select 1 from mytable t2

where t1.id = t2.related

and t2.id ='4')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值