I have the following database structure:
- id
- name
- year
- director
- runtime
An example entry being: (1, "Titanic", 1994, "James Cameron", 02:44:00)
I want to find a match by any three of the four criteria, for example:
1. name + year + director
2. name + year + runtime
3. year + director + runtime
If I created one index, would that be sufficient for optimial queries?
ALTER TABLE myTable ADD INDEX (name, year, director, runtime)
Or, do I need to create an index for each combination?
ALTER TABLE myTable ADD INDEX (name, year, director)
ALTER TABLE myTable ADD INDEX (name, year, runtime)
ALTER TABLE myTable ADD INDEX (year, director, runtime)
I would obviously prefer to use the first, but which would be suggested here? Why would one be preferable to the other? This is an InnoDB table.