我一直在考虑计算给定库存项目的现有单位数量的最佳方法。这些表格将非常大,包含许多交易,因此通过添加所有收货并减去所有发货和销售来计算按需计算可能不现实。我遇到的一个想法是定期创建检查点,即项目和现有数量的记录。任何后续的现有数量计算都从检查点开始,无需对所有交易求和。
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
在 8/30 上计算 inv 项目 1 的手头将是这样的
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
在 8 月 14 日计算 inv 项目 1 的手头将是这样的
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
我的问题是,这种方法会带来什么样的问题?除了将现有数量存储在表格中之外,还有其他更好的方法来处理大量事务集吗?将现有数量存储在表中是否与检查点方法几乎相同,如果通过触发器或某种信号进行更新,可能更不容易出错?