I would like to search my MYSQL db table by combinations of multiple attributes, and I would like to index it. For example, if this is my table :
+----+--------+--------+--------+--------+
| id | field1 | field2 | field3 | field4 |
+----+--------+--------+--------+--------+
| | | | | |
I want to run queries like these :
select * from table where field1=value1 and field2=value2;
select * from table where field3=value3 and field4=value4;
select * from table where field1=value1 and field2=value2 and field3=value3;
select * from table where field4=value4;
What is the best way to make an index for something like that?
CREATE INDEX my_index on table(field1, field2, field3, field4);
or something like :
CREATE INDEX my_index1 on table(field1);
CREATE INDEX my_index2 on table(field2);
CREATE INDEX my_index3 on table(field3);
CREATE INDEX my_index4 on table(field4);
or something else entirely?
EXPLAINoutput will indicate this.