Description of the default transaction isolation level of mysql and oracle

Description of the default transaction isolation level of mysql and oracle

1. Transaction characteristics (ACID)

(1) Atomicity. The database modification operations performed by the programs involved in the transaction either all succeed or all fail.

(2) Consistency The source and destination are balanced before and after the transaction is executed.

(3) Isolation During concurrency, each transaction is isolated and does not affect each other.

(4) Durability Once a transaction is successfully committed, the integrity of the data should be guaranteed.

2. Transaction Isolation Level

(1) read uncommitted

All transactions can see the data of uncommitted transactions.

(2) read committed

The transaction can only be queried after it is successfully submitted.

(3) Repeatable

When multiple instances of the same transaction read data, uncommitted records may be queried, resulting in phantom reads. mysql default level

(4) Serializable

Force sorting and add shared locks on each read data row. This will result in a lot of timeouts and lock contention.

MySQL

The default transaction level of MySQL is 'REPEATABLE-READ', which means repeatable read

1. View the current session isolation level

select @@tx_isolation;

2. View the current isolation level of the system

select @@global.tx_isolation;

3. Set the current session isolation level

set session transaction isolatin level repeatable read;

4. Set the current isolation level of the system

set global transaction isolation level repeatable read;

Oracle

Oracle database supports two transaction isolation levels: READ COMMITTED and SERIALIZABLE.

The default system transaction isolation level is READ COMMITTED, which means read committed

1. Check the system default transaction isolation level, which is also the current session isolation level

--First create a transaction

declare
 trans_id Varchar2(100);
 begin
 trans_id := dbms_transaction.local_transaction_id( TRUE );
 end;

-- Check the transaction isolation level

SELECT s.sid, s.serial#,

  CASE BITAND(t.flag, POWER(2, 28))
    WHEN 0 THEN 'READ COMMITTED'
    ELSE 'SERIALIZABLE'
  END AS isolation_level
FROM v$transaction t
JOIN v$session s ON t.addr = s.taddr AND s.sid = sys_context('USERENV', 'SID');

Supplement: SQLserver locks and transaction isolation levels

Isolation Level

Isolation Level Dirty Read Non-repeatable read phantom illustrate
Read uncommitted yes yes yes If other transactions are updated, execute immediately regardless of whether they are committed or not
Read committed (read committed by default) no yes yes Read submitted data. If other transaction updates are not committed, wait
Repeatable read no no yes During the query, other transactions are not allowed to update
serializable no no no During the query, other transactions are not allowed to insert or delete
Request Mode IS S U IX SIX X
Intention Sharing (IS) yes yes yes yes yes no
Share(S) yes yes yes no no no
Update (U) yes yes no no no no
Intention to Exclude (IX) yes no no yes no no
Shared exclusively with intent (SIX) yes no no no no no
Exclusive (X) no no no no no no

Lock

Shared lock: For shared read (select), if there is a transaction (one or more) with a shared lock on the data in the table (the amount of locked data depends on the granularity of the lock), the locked data is not allowed to be updated (update)

Exclusive lock: There can only be one, and other transactions cannot obtain shared locks and exclusive locks on the locked data (that is, exclusive locks are incompatible with shared locks. For more information, please see lock compatibility). Here we especially emphasize the locked data.

Locks and Isolation Levels

Type 1

① READUNCOMMITTED: No lock is issued

② READCOMMITTED: Issue a shared lock and hold it until the reading is completed

③ REPEATABLEREAD: Issue a shared lock and hold it until the end of the transaction

④ SERIALIZABLE: Issues a shared lock and holds it until the end of the transaction

Type 2

① NOLOCK: No lock is issued. Equivalent to READUNCOMMITTED

② HOLDLOCK: Issue a shared lock and hold it until the end of the transaction. Equivalent to SERIALIZABLE

③ XLOCK: Issues an exclusive lock and holds it until the transaction ends.

④ UPDLOCK: Issues an update lock and holds it until the transaction ends. (Update lock: does not block other things, allowing other things to read data (that is, update lock is compatible with shared lock), but it ensures that the data has not been updated since the last time it was read)

⑤ READPAST: Issues a shared lock, but skips locking the row, it will not be blocked. Applicable conditions: Commit read isolation level, row-level lock, select statement.

Type 3

① ROWLOCK: row-level lock

② PAGLOCK: Page-level lock

③ TABLOCK: table lock

④ TABLOCKX: table exclusive lock

Using XLOCK in a SELECT statement does not prevent reads. This is because SQL SERVER has a special optimization at the read committed isolation level, which checks whether the row has been modified and ignores XLOCK if it has not been modified. Because this is indeed acceptable in the Read Committed isolation level.

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • How to choose transaction isolation level in MySQL project
  • Detailed explanation of transaction isolation levels in MySql study notes
  • Detailed explanation of the implementation principle of transaction isolation level in MySQL
  • Briefly describe the four transaction isolation levels of MySql
  • Mysql case analysis of transaction isolation level

<<:  Vant uploader implements the drag-and-drop function for uploading pictures (set as cover)

>>:  Tomcat uses thread pool to handle remote concurrent requests

Recommend

Detailed explanation of the steps to build a Vue project with Vue-cli

First you need to install Vue-cli: npm install -g...

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Book page turning effects made with CSS3

Result:Implementation code: html <!-- Please h...

Vue implements the shake function (compatible with ios13.3 and above)

Recently, I made a function similar to shake, usi...

Understanding JavaScript prototype chain

Table of contents 1. Understanding the Equality R...

The past two years with user experience

<br />It has been no more than two years sin...

How to automatically number the results of MYSQL query data

Preface In fact, I have never encountered this ki...

Detailed explanation of Cgroup, the core principle of Docker

The powerful tool cgroup in the kernel can not on...

5 Commands to Use the Calculator in Linux Command Line

Hello everyone, I am Liang Xu. When using Linux, ...

Echarts tutorial on how to implement tree charts

Treemaps are mainly used to visualize tree-like d...

Implementation of Vue single file component

I recently read about vue. I found a single-file ...

Play mp3 or flash player code on the web page

Copy code The code is as follows: <object id=&...