📜 ⬆️ ⬇️

DBMS transactions

All beaver! We are actively expanding our, so to speak, range of courses, and now we are pleased to present a new one: “Relational DBMS” . The course was created by one of the leading teachers of the Linux Administrator course, Alexey Tsykunov . Otherwise, everything will be as usual: usefulness and open lessons , in which Aleksey will share different things that are not included in the course itself.

Go!

A transaction can be defined as a set of tasks, the execution of which is a prerequisite for the correct completion of a transaction. A single task is the minimum indivisible data change block.

We give an example of a simple transaction. Suppose a bank employee transfers 500 rupees from account A to account B. This small and simple transaction involves several low-level tasks.
')
Account A

Open_Account(A) Old_Balance = A.balance New_Balance = Old_Balance - 500 A.balance = New_Balance Close_Account(A) 

Account B

 Open_Account(B) Old_Balance = B.balance New_Balance = Old_Balance + 500 B.balance = New_Balance Close_Account(B) 




ACID properties

A transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability - abbreviated as ACID - to ensure accuracy, completeness, and integrity of data:


Serialization

When multiple transactions are executed by the operating system in a multiprogram environment, it is likely that the instructions of one transaction will be mixed with the instructions of another.


In a multitransactional environment, a consistent schedule is considered a benchmark. The order of execution of instructions in a transaction cannot be changed, but the execution of instructions of two transactions may be random. Execution does not do any harm when the two transactions are mutually independent and work on different data segments; but if they use the same data, the results may differ, which may lead the database to an inconsistent state.

To solve this problem, we allow parallel execution of a transaction schedule if transactions are serialized or have some equivalence relation.

Equivalent schedules

Equivalent schedules can be of the following types:

Equivalence of the result

If two schedules after execution give the same result, they are considered equivalent in result. Results may be the same for some values ​​and different for another set of values. Therefore, this equivalence is usually not considered significant.

Representation equivalence

Two schedules are considered equivalent in representation in the event that transactions in each of the schedules perform similar actions in a similar way.

For example:


Conflict equivalence

Two schedules will conflict if they have the following properties:


Two schedules with multiple transactions with conflicting operations are considered equivalent to a conflict only if:


Note - Schedules equivalent in representation are serializable in representation, and conflict-equivalent are conflict-serializable. All conflict-serializable schedules are serializable by submission.

Transaction States

A transaction in a database can be in the following states:




THE END

As always, we are waiting for comments, a question that can be asked both here and in the open lesson with Alexey .

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


All Articles