这篇文章介绍的内容是关于php面试的总结,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
面试问题
1. explain
内容导航
-
id
-
select_type
-
table
-
type
-
possible_keys
-
key
-
key_len
-
ref
-
rows
-
Extra
环境准备
MySQL版本:
创建测试表
CREATE TABLE people( id bigint auto_increment primary key, zipcode char(32) not null default '', address varchar(128) not null default '', lastname char(64) not null default '', firstname char(64) not null default '', birthdate char(10) not null default '' ); CREATE TABLE people_car( people_id bigint, plate_number varchar(16) not null default '', engine_number varchar(16) not null default '', lasttime timestamp );
插入测试数据
insert into people (zipcode,address,lastname,firstname,birthdate)values ('230031','anhui','zhan','jindong','1989-09-15'), ('100000','beijing','zhang','san','1987-03-11'), ('200000','shanghai','wang','wu','1988-08-25') insert into people_car (people_id,plate_number,engine_number,lasttime) values (1,'A121311','12121313','2013-11-23 :21:12:21'), (2,'B121311','1S121313','2011-11-23 :21:12:21'), (3,'C121311','1211SAS1','2012-11-23 :21:12:21')
创建索引用来测试
alter table people add key(zipcode,firstname,lastname);
EXPLAIN 介绍
先从一个最简单的查询开始:
Query-1 explain select zipcode,firstname,lastname from people;
EXPLAIN)本文来(源gaodai#ma#com搞@@代~&码*网2
搞代gaodaima码
输出结果共有id,select_type,table,type,possible_keys,key,key_len,ref,rows和Extra几列。
id
Query-2 explain select zipcode from (select * from people a) b;