I have been thinking about the best way to calculate the amount of on-hand units for a given inventory item. The tables will be very large, with many transactions so it may not be realistic to calculate on-hand on demand by adding all receivings and subtracting all shipments and sales. One idea I have come across is to periodically create checkpoints, i.e. records of item and and on-hand quantity. Any subsequent calculations of on-hand quantity start from the checkpoint forward, negating the need to sum over all transactions.
inventory item table
id | location | item
1 1 234
2 1 567
receiving table
inv item | stamp | quantity
1 2010-08-10 200
1 2010-08-30 10
2 2010-08-30 20
shipment table
inv item | stamp | quantity
1 2010-08-10 40
1 2010-08-30 5
2 2010-08-30 2
sale table
inv item | stamp | quantity
1 2010-08-10 10
1 2010-08-15 15
1 2010-08-30 1
1 2010-08-30 1
2 2010-08-30 2
checkpoint table
inv item | stamp | quantity
1 2010-08-11 150
1 2010-08-28 135
2 2010-08-15 15
Calculating on hand for inv item 1 on 8/30 would be like this
get most recent checkpoint(inv item 1, 8/30) returns 135 units on 8/28
on-hand = 135 + receivings - (shipments + sales)
only rcv/shp/sales that occur between the most recent checkpoint 8/30
Calculating on hand for inv item 1 on 8/14 would be like this
get most recent checkpoint(inv item 1, 8/14) returns 150 units on 8/11
on-hand = 150 + receivings - (shipments + sales)
only rcv/shp/sales that occur between the most recent checkpoint and 8/14
My question is, what sort of problems does this approach pose? Are there any better approaches for dealing with enormous transaction sets other than storing the on-hand quantity in a table? Is storing the on-hand quantity in a table almost the same as the checkpoint method, perhaps even less prone to error if updated via triggers or some sort of signals?