Oracle - How does Oracle manage transaction specific DML statements

前端 未结 4 1087
-上瘾入骨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:44

    Unless a particular constraint is "deferred", it will be checked at the point of the statement execution. If it is deferred, it will be checked at the end of the transaction. I'm assuming you did not defer your PRIMARY KEY and that's why you get a violation even before you commit.

    How this is really done is an implementation detail and may vary between different database systems and even versions of the same system. The application developer should probably not make too many assumptions about it. In Oracle's case, PRIMARY KEY uses the underlying index for performance reasons, while there are systems out there that do not even require an index (if you can live with the corresponding performance hit).

    BTW, a deferrable Oracle PRIMARY KEY constraint relies on a non-unique index (vs non-deferrable PRIMARY KEY that uses a unique index).

    --- EDIT ---

    I just realized you didn't even commit the first INSERT. I think Justin's answer explains nicely how what is essentially a lock contention causes one of the transactions to stall.

提交回复
热议问题