In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `users` ADD INDEX `users_idx_ref_id` (`ref`,`id`);
SELECT
a.id,
(SUM(SELECT
users.col_add_1 + users.col_add_2
FROM
users
WHERE
users.ref = a.id)) AS total
FROM
users a