Transaction isolation when selecting, inserting, deleting

What could be wrong in the next transaction if executed by concurrent users at the default isolation level READ COMMITTED?

BEGIN TRANSACTION

SELECT * FROM t WHERE pid = 10 and r between 40 and 60
-- ... this returns tid = 1, 3, 5
-- ... process returned data ...
DELETE FROM t WHERE tid in (1, 3, 5)
INSERT INTO t (tid, pid, r) VALUES (77, 10, 35)
INSERT INTO t (tid, pid, r) VALUES (78, 10, 37)
INSERT INTO t (tid, pid, r) VALUES (79, 10, 39)

COMMIT
+3
source share
4 answers

You may have serious performance issues from dead castles

SELECT will receive a shared lock on the page, and then DELETE will try to update these locks to exclusive locks.

, . , , . , . , , . , , , . , , , .

- , , get-go. concurrency , .

+3
. ? . , . , , , , , , , , tid tid, pid combo.

, ? , , . .

+1

, oracle postgres. , . .

0

SELECT, , tid 1, 3 5. , . , . , . , ( , ) . , ?

, , SELECT ... FROM ... FOR UPDATE; , . http://www.postgresql.org/docs/8.4/interactive/sql-select.html

0

Source: https://habr.com/ru/post/1739908/


All Articles