????explain?????mysql????????????????select????????????????????????????????д??????????????
????1???????????
??????????sql??????£?
/*
Navicat MySQL Data Transfer
Source Server         : localhost-newpassword
Source Server Version : 50550
Source Host           : localhost
Source Database       : testExplain
Target Server Version : 50550
File Encoding         : utf-8
Date: 08/05/2016 18:06:12 PM
*/
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
--  Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL??
`name` varchar(30) NOT NULL??
`age` int(11) NOT NULL??
`sex` tinyint(4) NOT NULL??
`isDeleted` tinyint(4) NOT NULL??
PRIMARY KEY (`id`)??
UNIQUE KEY `id_unidx` (`id`) USING BTREE??
UNIQUE KEY `name_unidx` (`name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- ----------------------------
--  Records of `user`
-- ----------------------------
BEGIN;
INSERT INTO `user` VALUES ('1'?? 'wwwwe'?? '11'?? '1'?? '0')?? ('2'?? '222'?? '22'?? '1'?? '0')?? ('3'?? '2222'?? '10'?? '0'?? '0');
COMMIT;
SET FOREIGN_KEY_CHECKS = 1;
????2??explain??÷???
??????÷???????select????????explain ????????磺
????explain select * from user where id = 1
?????????
????+----+-------------+-------+-------+------------------+---------+---------+-------+------+-------+
????| id | select_type | table | type  | possible_keys    | key     | key_len | ref   | rows | Extra |
????+----+-------------+-------+-------+------------------+---------+---------+-------+------+-------+
????| 1  | SIMPLE      | user  | const | PRIMARY??id_unidx | PRIMARY | 4       | const | 1    |       |
????+----+-------------+-------+-------+------------------+---------+---------+-------+------+-------+
????3??explain????????????
????id??select???????????select??????к????????????????????sql?????е????
????select_type????????漸?????
????simple ?????????select?????union??????
????primary ?????select????????????????У??????select?????primary
????union union???????????????????????.
????dependent union    UNION?е???????????SELECT???????????????
????union result        UNION????
????table:?????????????
????type:????????????????????????????????????const??eq_reg??ref??range??indexhe??all
????const??????????????У?const??????primary key ????unique?????????????????????????????????????primary key ????unique