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 `exclusion_policies` ADD INDEX `exclusion_policies_idx_active_client_mcc_mnc` (`active`,`client_id`,`mcc`,`mnc`);
SELECT
r.id,
IF(exp.id != 0,
1,
IF(exp2.id != 0,
1,
IF(exp3.id != 0,
1,
0))) AS white_list
FROM
rates AS r
LEFT JOIN
exclusion_policies AS exp
ON (
1 = 1
AND exp.client_id = r.client_id
AND exp.mcc = r.mcc
AND exp.mnc = r.mnc
AND exp.active = 1
)
LEFT JOIN
exclusion_policies AS exp2
ON (
1 = 1
AND exp2.client_id = r.client_id
AND exp2.mcc = r.mcc
AND exp2.active = 1
)
LEFT JOIN
exclusion_policies AS exp3
ON (
1 = 1
AND exp3.client_id = r.client_id
AND exp3.active = 1
)