Skip to content

Fixes ISSUE-49339: Added c_period to index for table fact_acct to improve the performance of table FinancialMgmtAccountingFactEndYearHQL

Igor Trebol requested to merge openbravo/devel/openbravo:fix/49339 into master

Improved the query for table (FinancialMgmtAccountingFactEndYearHQL) adding c_period index for table fact_acct. This changes the query time from ~15 minutes to less than 10s. It could still be improved by modifying the HQL query with something like (with insertion points), being the period ids the ids of all the periods from the year selected in the window.

SELECT max(fa.id) AS Fact_Acct_End_Year_V_ID, fa.client.id AS AD_Client_ID, pc.organization.id AS AD_Org_ID, Max(fa.creationDate) AS Created, Max(fa.createdBy.id) AS Createdby, Max(fa.updated) AS Updated, Max(fa.updatedBy.id) AS Updatedby, Max(fa.active) AS Isactive, Max(fa.id) AS Fact_Acct_ID, Max(fa.description) as Description, pc.id AS C_Year_Close_V_ID, (select asch.name from FinancialMgmtAcctSchema asch where fa.accountingSchema.id = asch.id) AS C_Acctschema_ID, (select ev.searchKey from FinancialMgmtElementValue ev where fa.account.id = ev.id) AS Account_ID, fa.type AS Factaccttype, CASE WHEN Sum(fa.debit - fa.credit) > 0 THEN Sum(fa.debit - fa.credit) ELSE 0 END AS Debit, CASE WHEN Sum(fa.credit - fa.debit) > 0 THEN Sum(fa.credit - fa.debit) ELSE 0 END AS Credit FROM FinancialMgmtAccountingFact fa JOIN fa.period p JOIN p.financialMgmtPeriodControlList pc WHERE fa.type IN ('O', 'C', 'D', 'R') AND p.id IN (:periodIds) AND pc.id = :periodControlId AND @additional_filters@ GROUP BY fa.client.id, pc.id, fa.accountingSchema.id, fa.account.id, fa.type, p.year.id, pc.organization.id HAVING Sum(fa.credit - fa.debit) <> 0

Edited by Igor Trebol

Merge request reports