It is important to create good indexes so that your queries do not unnecessarily need to scan many rows, that can result in lock on those rows and due to which deadlocks can occur, performance can be degraded, or anything bad can happen.
If result of a function is needed more than once then don’t call that function multiple times. Save the result of that function in a variable and use that variable instead.