Statement 1:
Select id, name, sex from table_name where ((sex=1 and (name like 'a %')) or (sex=0 and (name like '%' lee)))
Statement 2:
Select id, name, sex from table_name where (((name like 'a %') and sex=1) or ((a name like '%' li) and sex=0))
Question, when sex in the where clause structure and influential position name order?
(for example, sex=0 and (name like '%' lee)), if a full table of sex field value is 1, then the mysql does not (name like '%' lee) query?
Or sex and name will enter the query process?
CodePudding user response:
Sex or name, the mysql eventually walk which indexes, such as sex index scan line number less than the name index, then the mysql will use sex index, if the record is 0 natural need not more the name,If haven't indexed, then scan the whole table, each line to do matching conditions, is go go first sex or name is bad to say, but do not have what difference on efficiency
CodePudding user response:
The