title: Mysql query with user-defined-function - why function was called twice?
body: <p>I have a 1:1 relation between tables Entity and Contact (that corresponds to object 's inherirance). fn_match(id) is UDF which returns boolean and returns true if record matches some special criteria (additional queries inside function). That's a query:</p>
  
  <pre><code>select *
  from Entity a
  inner join Contact b on a.id = b.id
  where fn_match(a.i)
  </code></pre>
  
  <p>It worked fine but join spoils performance dramatically.
  I have added logging and have found that fn_match was called twice for every record in Entity with fn_match(id) = true. I could fix it adding deterministic to function header, but I used to think that every function/stored procedure accessing tables' data is non-deterministic.</p>
  
  <p>What is correct solution for this issue?  </p>