Answer the question
In order to leave comments, you need to log in
How will a SQL query with an ORDER BY expression work?
There is a SQL query that is supposed to work under SQLite and MySQL:
SELECT id, name, col1, col2 FROM table ORDER BY col2/col1 ASC
Answer the question
In order to leave comments, you need to log in
one-time for each row of the table
firstly, these are not arrays, and secondly, sorting does not work that way.
The order in which data is read from disk does not guarantee order.
I think that:
first, rows will be read and col2 / col1 will be calculated,
then sorting
and the result of the query will go to the database cache in the RAM.
Therefore, if you request in a row, the cached result will be returned.
But this is not accurate, because you need to know how the query optimizer works inside, statistics affect query execution, i.e. non-deterministic operation.
Therefore, you need to measure performance locally if this is a bottleneck. And if not, then don’t worry too much about such trifles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question