Oracle - How does Oracle manage transaction specific DML statements

前端 未结 4 1122
-上瘾入骨i
-上瘾入骨i 2021-01-22 11:57

Imagine I have this simple table:

Table Name: Table1
Columns:    Col1 NUMBER (Primary Key)
            Col2 NUMBER

If I insert a record into Ta

4条回答
  •  没有蜡笔的小新
    2021-01-22 12:39

    Oracle creates an index to enforce the primary key constraint (a unique index by default). When Session A inserts the first row, the index structure is updated but the change is not committed. When Session B tries to insert the second row, the index maintenance operation notes that there is already a pending entry in the index with that particular key. Session B cannot acquire the latch that protects the shared index structure so it will block until Session A's transaction completes. At that point, Session B will either be able to acquire the latch and make its own modification to the index (because A rolled back) or it will note that the other entry has been committed and will throw a unique constraint violation (because A committed).

提交回复
热议问题