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

时间:2013-04-07 12:38:12

标签: performance firebird

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

在我看来,选项是:

  1. 将其保存在一行中,
  2. 使用触发器将更改保存到单独的表中
  3. 使用select | update进行更新
  4. 使用表格中的简单选择来访问值
  5. 替代方案是:

    1. 将值保存在单独的表中,
    2. 使用选择上一个和插入来实现更新
    3. 使用从单独表格中选择最后一个来访问值
    4. 有谁知道哪个更快?它有多少?

      史蒂夫

1 个答案:

答案 0 :(得分:0)

你提出的建议似乎太复杂了...... 我会做一些不同的事情: 我会有两个表与主 - 细节关系。 在详细信息中,我将插入行,其触发器将更新主表

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

任何更改后,您只需关闭/打开主表即可刷新数据。