Understanding EXPLAIN Result in MySQL

I have two split requests that have the same outputs. Now I'm trying to figure out which one is better?

Query1:

| 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 |

So which one is better and why?

I read about EXPLAINhere , but still I don't know which parameter is important? Or what parameter shows me that such a column should be an index, or should my query be optimized?

In these two explanations above, all columns are identical except: select_typeand extra. So which one is better:

    • SIMPLE, SIMPLE
    • PRIMARY, DEPENDENT SUBQUERY
    • Using where, Using where; Using join buffer (Block Nested Loop)
    • Using where, Using where

EDIT: Here are two queries:

Query1:

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')
+4
source share
1 answer

possible keys: NULL. . 9 , . . 9 * 9 = 81 . 1000 , 1000000 , .

1 - ().

() , .

, PRIMARY KEY(id). , SHOW CREATE TABLE mytable.

EXPLAIN . , EXPLAIN.

0

All Articles