简体   繁体   中英

Complex accounting calculations from a slow temporary table

I have been tasked to write a complicated invoicing and billing system with reports. The structure of the database is such that returning the invoices' totals and figures requires a complicated string of joins and calculations that is cumbersome to troubleshoot and highly sensitive to error.

Rather than produce a library of long and complicated queries throughout my reporting system, I opted to use a temporary table that will perform the necessary calculations and hold the figures next to a record ID number that I can join into when and where needed. This made coding the system much easier, but it also made the database noticeably slower as every page hit that needs to use this temp table must populate it first.

In summary, I've got a reporting system that must be able to display calculated figures from a series of several invoice tables. Can anyone offer advice on an approach or solution that would simplify this process without costing me server speed?

Hard to judge as your description is too generic.

One of the possible solutions: If the reports you are generating allow to be a little outdated, then you could create a regular table instead of a temporary one and populate it with all the info using an event scheduler as often as needed (eg once a day or once an hour).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM