火鸟性能:更新/选择vs插入/最后选择



我必须保持最新的账户余额,记录更改,并使用它。

在我看来,选项是:

  1. 保持单行,
  2. 使用触发器将更改保存到单独的表
  3. 使用select|update执行更新
  4. 使用简单的select从表中访问值

可选:

  1. 将值保留在单独的表中,
  2. 使用Select Last和Insert来实现更新
  3. 使用单独表中的Select Last来访问值

有人知道哪个更快吗?里面有很多东西吗?

史蒂夫

你的建议似乎太复杂了…我建议做一件不同的事情:我将有两个具有主从关系的表。在细节中,我将插入行,它的触发器将更新主表

balance (account, amount, ...)
balance_detail (account, amount, ...)
balance_detail_after_insert
begin
    update master
    set amount = amount + new.amount
    where account = new.account;
end
balance_detail_after_update
begin
    update master
    set amount = amount + new.amount - old.amount
    where account = new.account;
end
balance_detail_after_delete
begin
    update master
    set amount = amount - new.amount
    where account = new.account;
end
修改后,只需关闭/打开主表即可刷新数据。

最新更新