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_status_id_previousba` (`Status`,`ID`,`PreviousBalance`);
ALTER TABLE `Ledger` ADD INDEX `ledger_idx_accountid` (`AccountId`);
SELECT
(coalesce(sum(Ledger.Debit),
0) - coalesce(sum(Ledger.Credit),
0)) + Accounts.PreviousBalance[Balance]
FROM
Accounts
LEFT JOIN
Ledger
ON Accounts.ID = Ledger.AccountId
WHERE
Accounts.Status = 'Active'
GROUP BY
Accounts.ID,
Accounts.PreviousBalance
ORDER BY
NULL