In order for MySQL to sort the results by the calculated value, it really needs to calculate the value "on the fly" after it has filtered the rows based on the WHERE . If the result set is large enough, MySQL will have to calculate the results for all rows.
For a small set of results, this should be good. However, the larger your result set (before applying LIMIT ), the more calculations the server needs to do, just calculates the value to arrange the strings. If the calculation is deterministic, you should cache this in a column in the result set, and then index it. If it is on the fly, you will need to make sure that your processor is suitable for the task.
In this case, I would recommend creating a.field_3 column and storing the result in it (a.field_1*a.field_2) . Whenever the values ββof a.field_1 or a.field_2 change, you will need to recalculate the result.
source share