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 `bill` ADD INDEX `bill_idx_account_num_effective_date` (`account_num`,`effective_date`);
SELECT
bill1.account_num,
bill1.effective_date AS ed1,
bill1.amount AS am1,
bill3.effective_date AS ed2,
bill3.amount AS am2
FROM
bill AS bill1
LEFT JOIN
bill AS bill3
ON (
bill1.account_num = bill3.account_num
)
LEFT JOIN
bill AS bill2
ON (
bill2.account_num = bill1.account_num
)
AND (
bill1.effective_date < bill2.effective_date
)
LEFT JOIN
bill AS bill4
ON (
bill4.account_num = b1.account_num
AND bill4.effective_date < (
SELECT
max(bill.effective_date)
FROM
bill
WHERE
bill.account_num = b1.account_num
)
)
AND (
bill3.effective_date < bill4.effective_date
)
WHERE
(
(
1 = 1
AND (
1 = 1
OR bill3.effective_date IS NULL
)
)
AND (
bill2.effective_date IS NULL
)
)
AND (
bill4.effective_date IS NULL
)
ORDER BY
bill1.effective_date DESC