Nick Trainor <nick.trainor@trainorthornton.co.uk> writes:
> What am I missing here?
The ORDER BY query has to evaluate the function at *every* row of the
table before it can sort. The other query was only evaluating the
function at twenty rows.
regards, tom lane