| ▲ | soontimes 2 hours ago | |||||||||||||||||||||||||||||||||||||
Ok, but before inserting you must ensure that inventory is not depleted, which means you need to know the count and you need to lock the row. So you still have contention on that item. Them having a 1k buffer allows not to take a lock on a single row every time, and only do it when buffer is empty | ||||||||||||||||||||||||||||||||||||||
| ▲ | bijowo1676 an hour ago | parent [-] | |||||||||||||||||||||||||||||||||||||
there is no need to lock the row, since you a dealing with a shopping cart, not individual item piece. when you run aggregate functions, lock is no needed, it is actually better to run it with SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; for aggregation the check for oversold items is extremely cheap:
assuming there are indexes on sku field in both, results in efficient index seek and agg over 2 tables | ||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||