What does MySQL perform first: The WHERE clause or the ORDER BY clause?
The reason I ask is to determine whether I should add an index to a given column.
I have a table such as the following:
| Column | Type | Index |
|-----------|-------------|-------|
| id | INT (pk) | Yes |
| listorder | INT | ?? |
| data | VARCHAR(16) | No |
| fk | INT (fk) | Yes |
I will often execute queries such as SELECT id, data FROM mytable WHERE fk=12345 ORDER BY listorder ASC. For my data set, it will only result in a small number of records (~5) for a given fk, however, there are many records in the table with many fk values, and many duplicated listorder values spanning the many fk values.
If the WHERE clause is performed first, then I expect I shouldn't add an index to listorder as it will result in UPDATE performance degradation without significant improvement for SELECT.