It stumbled upon me while I was reading the query in another post.
Take the following query for example (ignore the non-practical use of the ordering):
SELECT
*
FROM Members
ORDER BY (TIMESTAMPDIFF(FRAC_SECOND, DateCreated , SYSDATE()))
Say "Members" table has a huge row count (or the query is complex enough for it to be executed over at least dozen of milliseconds). How does mySQL or other mainstream DB engines evaluate the "SYSDATE()
" in the "ORDER BY
"?
Say the query takes half a second, the microsecond (FRAC_SECOND
) of "SYSDATE" changes 1000 X 1000 X 0.5 = 500 000 times.
My questions are:
- Does the "SYSDATE" get fixed on the start of the query execution or it gets evaluated and changes as the execution progresses?
- If it's the latter, can I assume the ordering might be jumbled?
UPDATE:
My original post uses NOW
as an example of dynamic value, it's SYSDATE
now