国税网站模板,做网站知识大全,wordpress媒体文件,泸州建设工程质量监督网站对于mysql建表稍有点经验的开发人员都会为后续的where查询条件提前考虑创建索引。这里说的是在使用索引查询时有关索引下推的有关知识点。综合前人的经验结果#xff1a;索引下推是数据库检索数据过程中为减少回表次数而做的优化。判断是否需要回表的是由mysql存储引擎控制索引下推是数据库检索数据过程中为减少回表次数而做的优化。判断是否需要回表的是由mysql存储引擎控制默认从mysql5.6版本开始支持。下面用docker分别创建基于mysql5.5和mysql5.6的容器表结构保持一致(docker创建mysql容器不做演示)。首先看mysql5.5mysql select version();-----------| version() |-----------| 5.5.62 |-----------1 row in set (0.00 sec)mysql show create table testhh\G;*************************** 1. row ***************************Table: testhhCreate Table: CREATE TABLE testhh (id int(10) unsigned NOT NULL,age int(10) unsigned DEFAULT 0,name char(10) NOT NULL DEFAULT ,height int(10) NOT NULL DEFAULT 0,name2 char(10) NOT NULL DEFAULT ,height2 int(10) NOT NULL DEFAULT 0,PRIMARY KEY (id),KEY age_index (age) USING HASH,KEY un (name,height)) ENGINEInnoDB DEFAULT CHARSETlatin11 row in set (0.00 sec)ERROR:No query specifiedmysql explain select * from testhh where name like a% and height 100\G;*************************** 1. row ***************************id: 1select_type: SIMPLEtable: testhhtype: rangepossible_keys: unkey: unkey_len: 14ref: NULLrows: 1Extra: Using where1 row in set (0.00 sec)ERROR:No query specified上面可见explain的extra字段结果时Using where表示优化器需要通过索引回表查询数据。再看mysql5.6:mysql selectversion();-----------| version() |-----------| 5.6.50 |-----------1 row in set (0.00sec)mysqlshow create table ua\G;*************************** 1. row ***************************Table: uaCreate Table: CREATE TABLE ua (idint(10) NOT NULL AUTO_INCREMENT,namechar(10) NOT NULL DEFAULT ,heightint(10) NOT NULL DEFAULT 0,name2char(10) NOT NULL DEFAULT ,height2int(10) NOT NULL DEFAULT 0,PRIMARY KEY (id),KEY nh (name,height)) ENGINEInnoDB DEFAULT CHARSETlatin11 row in set (0.00sec)ERROR:No query specifiedmysql explain select * from ua where name like a% and height10\G;*************************** 1. row ***************************id:1select_type: SIMPLEtable: uatype: rangepossible_keys: nhkey: nhkey_len:14ref: NULLrows:1Extra: Using index condition1 row in set (0.00sec)ERROR:No query specifiedexplain的extra字段是Using index condition表示会先通过条件过滤索引再通过过滤后的索引查询符合索引条件的数据。