技术开发 频道

MySQL Explain 详解

  (4).UNION RESULT

  UNION的结果。

  mysql> explain select * from t3 where id=3952602 union all select * from t3 ;

  +----+--------------+------------+-------+-------------------+---------+---------+-------+------+-------+

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

  +----+--------------+------------+-------+-------------------+---------+---------+-------+------+-------+

  | 1 | PRIMARY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | |

  | 2 | UNION | t3 | ALL | NULL | NULL | NULL | NULL | 1000 | |

  |NULL | UNION RESULT | | ALL | NULL | NULL | NULL | NULL | NULL | |

  +----+--------------+------------+-------+-------------------+---------+---------+-------+------+-------+

  (5).SUBQUERY

  子查询中的第一个SELECT.

  mysql> explain select * from t3 where id = (select id from t3 where id=3952602 ) ;

  +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------------+

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

  +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------------+

  | 1 | PRIMARY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | |

  | 2 | SUBQUERY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | Using index |

  +----+-------------+-------+-------+-------------------+---------+---------+-------+------+-------------+

  (6). DEPENDENT SUBQUERY

  子查询中的第一个SELECT,取决于外面的查询

  mysql> explain select id from t3 where id in (select id from t3 where id=3952602 ) ;

  +----+--------------------+-------+-------+-------------------+---------+---------+-------+------+--------------------------+

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

  +----+--------------------+-------+-------+-------------------+---------+---------+-------+------+--------------------------+

  | 1 | PRIMARY | t3 | index | NULL | PRIMARY | 4 | NULL | 1000 | Using where; Using index |

  | 2 | DEPENDENT SUBQUERY | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | const | 1 | Using index |

  +----+--------------------+-------+-------+-------------------+---------+---------+-------+------+--------------------------+

  (7).DERIVED

  派生表的SELECT(FROM子句的子查询)

  mysql> explain select * from (select * from t3 where id=3952602) a ;

  +----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+

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

  +----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+

  | 1 | PRIMARY | | system | NULL | NULL | NULL | NULL | 1 | |

  | 2 | DERIVED | t3 | const | PRIMARY,idx_t3_id | PRIMARY | 4 | | 1 | |

  +----+-------------+------------+--------+-------------------+---------+---------+------+------+-------+

  

0
相关文章