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 `accounts` ADD INDEX `accounts_idx_id_user_id_currency` (`id`,`user_id`,`currency`);
ALTER TABLE `dense_balance_transactions` ADD INDEX `dense_transactions_idx_action_created_at` (`action`,`created_at`);
SELECT
MAX(user_id) AS user_id,
SUM(sum_amount_win) AS sum_amount_win
FROM
(SELECT
a1.user_id,
CASE
WHEN MAX(currency) = 'RUB' THEN SUM(d1.amount_cents) END AS sum_amount_win
FROM
dense_balance_transactions AS d1
JOIN
accounts a1
ON a1.id = d1.account_id
JOIN
(
VALUES
(5), (
22
), (
26
)
) AS v(user_id) USING (user_id)
WHERE
d1.created_at BETWEEN '2019-06-01 00:00:00' AND '2019-06-20 23:59:59'
AND d1.action = 'win'
GROUP BY
a1.user_id,
a1.currency
ORDER BY
NULL) AS t
GROUP BY
user_id
ORDER BY
NULL