Details
Description
When invoices are generated there is a sub-optimal query being run.
SELECT SUM(`transaction_applied`.`amount`) AS `total` FROM `transaction_applied` INNER JOIN `invoices` ON `invoices`.`id` = `transaction_applied`.`invoice_id` WHERE `invoices`.`status` IN ('active','proforma') AND `invoices`.`currency` = 'USD' AND `invoices`.`client_id` = '12693' AND `invoices`.`date_closed` IS NULL AND `invoices`.`date_billed` <= '2015-03-19 15:55:19' GROUP BY `invoices`.`client_id`
Solution is to add an index for invoice ID on transaction_applied:
OR
Above not needed since the number of transactions applied to each invoice is very small.