MySQL automatically optimizes your query, so that the function is called only once, and the result will be reused.
If you want to avoid repeated code, you can evaluate the function in the view and then query for it.
SELECT blah
FROM
(
SELECT
blah, field1, field2, field3,
functCall(otherField1, otherField2) AS f
FROM your_table
) T1
WHERE field1 % f = 0
OR field2 % f = 0
OR field3 % f = 0
source
share