Please help to make Mysql index For multiple where conditions Example :
Select id from table_name where col1='' and col2='' and col3='' and col4=''
and col5=''and col6='';
Now number of combinations of where conditions ,First two columns col1 and col2 is fix ; other combinations IS:-
where col1='' and col2='' and col3='' ;
where col1='' and col2='' and col3='' and col4='';
where col1='' and col2='' and col3='' and col4=''and col5='';
where col1='' and col2='' and col5=''and col6='';
where col1='' and col2='' and col4=''and col5=''and col6='';
where col1='' and col2='' and col4='' and col6=''
where col1='' and col2='' and col4='';
where col1='' and col2='' and col5='';
where col1='' and col2='' and col6='';
where col1='' and col2='' and col3='' and col5='';
I have only one Index
create INDEX `allpair` ON TABLE_NAME (col1,col2,col3,col4,col5,col6);
Please Help to make what is proper index for according these all where combinations. Thanks in advance.
allpairwill not cover every one of the queries in your list. If you have a composite index on(col1, col2, col3), then only where clauses oncol1,(col1, col2), or(col1, col2, col3)will use the index.