Problem description

MySQL 5.7.17-log table structure

create table address ( id int(11) unsigned auto_increment primary key, Id_no varchar(18) default "not NULL comment 'iD ', flow_id varchar(24) default" not null comment' iD ', Corp_name varchar(100) default 'not NULL comment ', city varchar(30) default' not null comment ', Tel varchar(13) null, type int(11) unsigned default 0 not NULL comment 'address class ', test_int int default 3 null); create index idx_flow_id on address (flow_id); create index idx_tel on address (tel);Copy the code

Where type stands for type and has only three values: 1, 2, null

Raw SQL

Select flow_id from api_address where corp_name=' Beijing 'and flow_id =' 2342352352352352353' and tel =' Beijing '0571-63035037' and type = 1 and test_int = 503 ;Copy the code

Optimized SQL

The optimized SQL can be viewed as follows:

select `address`.`flow_id` AS `flow_id` from `address` where ((`address`.`test_int` = 503) and (`address`.`type` = 1) and (`address`.`corp_name` = 'Beijing') and (`address`.`flow_id` = '2342352352352353') and (`api_address`.`city` = 'Beijing') and (`address`.`tel` = '0571-63035037'))
Copy the code

No matter how you adjust the order of the type and test_int columns, these two query conditions are always optimized first and appear in the order of which is followed and which is optimized first.

Excuse me, why is that?