mysql - Will a function will be recalled when I use its alias in ORDER BY clause? -
here simplified version of query:
select myfunc(u.id) score users u order score limit 20
as see, i've used score
(which result of myfunc()
function) in order by
clause. want know, function recalled when use in order by
clause? if yes, how can avoid that? because function needs lots of processing , recalling twice nightmare.
probably not, because data has been prepared time ordering done. if still have doubt, test making function visible between runs (increment value in table)
what may find though, runs million times, once each of million rows, before limit 20 can applied..
if function slow, , sensible store result upon insert rather calculate every time query run, that
Comments
Post a Comment