title: MySQL view generated using functions crash my app
body: <p>I have a view in my database (MySQL) that ranks users. It is generated generated by functions:</p>
  
  <pre><code>CREATE ALGORITHM=UNDEFINED SQL SECURITY INVOKER VIEW `users_ranks` AS select distinct `u`.`id` AS `id`, 
              `isUserVerified`(`u`.`id`) AS `verification`,
              `hasUserPicture`(`u`.`id`) AS `profile_picture`,
              `hasUserHobbies`(`u`.`id`) AS `hobbies`,
              ...
              ) AS total_value  
  
          from `users` `u`
  </code></pre>
  
  <p>this is an example of one of the functions called by the view:</p>
  
  <pre><code>CREATE FUNCTION hasUserPicture(user_id INT(10) UNSIGNED) RETURNS int(3)
              NO SQL
              DETERMINISTIC
              SQL SECURITY INVOKER
          BEGIN
              DECLARE hasPicture VARCHAR(191);
  
              SELECT
                  users.profile_picture
                  INTO
                  hasPicture
                  FROM
                  users
                  WHERE
                  users.id = user_id
              LIMIT 1;
  
              IF hasPicture IS NULL or hasPicture = '' THEN
                  RETURN 0;
              ELSE
                  RETURN 4;
              END IF;
          END;
  </code></pre>
  
  <p>There are lots of function calls in my view (update takes 21sec). The problem is that the view is updated whenever a user modifies information and with a large number of users makes the whole app run out of memory and crash. How can I fix the problem? Is there a better way to achieve the same result?</p>