+ 1

How can I secure a database table or a set of rows for writing?

I have a straightforward table with a main key. The majority of read operations return one row based on the precise value of the key. Each row's data has some link with the rows before and following it in the key order. So, when I insert a new row, I must first read the two rows between which it will enter, perform some computation, and then insert. Clearly, the problem is that another connection may simultaneously add a row with a key value in the same interval. If the key value is precisely the same, the second insert will fail, but if the key value is different but in the same interval, the relationship may be broken. When I decide to add a new row, the answer offered here (https://www.scaler.com/topics/dbms/serializability-in-dbms/) appears to be to lock the entire table for writing, or (if practicable, which I doubt) to lock an interval of key values. However, I would prefer that read-only transactions not be prohibited at that time. I misunderstood what you said. Can somebody assist me?

17th Jan 2023, 12:22 PM
sarthak jain
sarthak jain - avatar
1 Resposta