Subject [ib-support] Re: more deadlocks
Author Lauri Zoova
Pavel Cisar wrote:
>>I have a table with products(id, name, count) and another table with
>>sold_products(id, name, count, invoiceno.. etc). sold_products has a
>>trigger that fires on table insertions. It updates the count of products
>>in products table.
>
> Well, you have shoot yourself to the knees :)

I'd call it a trap. This looked like the most obvious and simple
solution :((

> The better approach is to never do an update connected with insert
> operation. In your case, you can sum() count of products sold from
> sold_products on demand.
> [...]

You mean, to add a computed field to products. something like - add
count_calc computed by (count - (select sum(s.count) from sold_products
s where s.id = id))?

This is a new approach worth exploring. Thanks Pavel.


BR,
Lauri