Below are the example query,How to add index with or clause ?
select fild1,fld2
from tablename
where (field3='XXXX' or field4='YYYY') and field6='xdffgfd';
Will the below index work ?
ALTER TABLE tablename ADD INDEX ind_name(field3,field4,field6);
No. This is not a good indexing strategy. The compound index you suggest will work for the
field3lookup, but it cannot work for thefield4lookup.You will need a separate index on
field4for that. If you provide a compound(field4, field6)index in addition to a(field3,field6)index you’ll optimize both parts of yourORclause for lookup, but you’ll incur an overhead on insertions and updates.