Lec-70: ACID Properties of a Transaction | Database Management System - YouTube

Channel: Gate Smashers

[0]
Hello friends!
[0]
Welcome to Gate Smashers
[2]
The topic is ACID properties in transaction
[5]
ACID properties is a very simple topic
[8]
This is purely a conceptual topic
[11]
Means one phenomena is there
[12]
Whenever we do implementation in real life
[16]
Like in today's time we are using any parties
[19]
Third party
[20]
Like Paytm is there
[21]
Many applications we are using
[23]
To execute transactions
[25]
Means payment is to be done
[27]
Bill payment is to be done
[28]
Or money is to be transferred
[30]
BHIM app is there of government of India
[33]
And we also have other 3rd party transactions
[36]
So these organizations
[38]
Who manage transactions
[40]
We cannot see these ACID properties
[43]
But all these 4 properties are used somewhere conceptually
[47]
We can also say them phenomena
[49]
They are 4 major properties
[51]
Atomicity, Consistency, Isolation and Durability
[55]
I am saying you first only
[56]
That these will not be seen in real life implementation
[59]
But somewhere as a developer
[62]
If anyone is working on backend
[64]
Then he knows that this 4 properties should be hold
[67]
If in real life scenario you are using transaction management system
[72]
So how this, I will explain with point of view of Gate
[76]
UGC-Net or your competitive exam point of view
[79]
First of all we'll talk automaticity
[82]
What is the meaning of automaticity property
[84]
If we see this from a simple way
[87]
Then automaticity is either all or null
[89]
Means, either all or null
[99]
Means if there is a transaction
[101]
Let's say transaction T1
[102]
And in transaction t1 there are many operations
[105]
Let's say read A
[107]
A=A-50
[109]
Write A
[110]
Read B
[111]
Read C
[113]
Many operations are there
[114]
This transaction is executing many operations
[117]
If transaction fails anywhere
[122]
If at any point it fails
[123]
Just before commit
[127]
If before commit it fails anywhere the transaction
[131]
Then we will rollback it
[133]
What we will do rollback
[135]
Means any operation on transaction
[139]
Will not be executed
[140]
All the operations
[142]
Will be rollback
[147]
This is the automaticity property
[149]
Which we are telling either all or none
[152]
Either all means that either all the operations will be executed
[154]
Until commit
[156]
After commit
[158]
If anyone says that transactions failed after commit
[161]
After commit no transaction can fail
[163]
Commit means in database
[165]
It is updated
[166]
When it is updated in database
[168]
Then there is no question to fail
[171]
So if just before commit
[174]
Transaction B fails
[176]
If I take a simple example
[177]
There are 100 operations
[179]
And if at 99th operation also transaction fails
[183]
Then over here there no pity
[185]
That my 99 were done
[186]
Or my transaction was 99% done, no
[189]
Whole transaction will be roll back
[193]
And it will again start, when? on some other time it will again start
[197]
But from 1st operation
[199]
So in simple way you can say this
[201]
A failed transaction cannot be resumed
[206]
A failed transaction will always restart
[210]
And if give you an example in real life scenario
[212]
Then if you do transaction from ATM
[215]
Or you do online transaction
[217]
So over there you perform some operations, what?
[219]
First we filled the username password
[221]
If I talk about online
[223]
Filled username password
[224]
Selected the beneficiary
[226]
You filled the amount
[227]
And let's say you entered the OTP
[230]
As you enter OTP your transaction fails
[232]
Session is out
[234]
Or internet got closed
[235]
Then what do you think, when you will again start the transaction
[238]
Will it start from that point only?
[240]
No
[241]
It will always restart
[243]
Even if we talk about ATM
[245]
We swiped the card
[246]
Selected the language
[248]
Entered the pin
[249]
You also selected the amount
[252]
But
[253]
After that if transaction fails
[255]
Then will the transaction again start from there only?
[259]
Never, transaction will always restart
[261]
Because we will rollback that transaction
[265]
Rollback means, we have to bring it to zero
[267]
You have to undo it
[269]
Till last
[270]
This is the meaning of Automaticity property
[273]
Either all until commit
[276]
Otherwise none of the operation
[278]
If transaction fails at 99 also
[280]
Then it will be completely rollbacked
[282]
It will restart it will not resume
[285]
This is not like normal downloading
[287]
That you are downloading, you are downloading some movie
[289]
And it is failed at 90%
[291]
So you can again start from 91
[294]
Or from 90, no
[294]
This is not a case of transaction
[297]
Second is consistency
[298]
On consistency you will get many material online material
[303]
You will get offline material
[304]
That this is consistency that is consistency
[306]
But as we talked about atomicity
[309]
In that way I am telling you about consistency
[311]
Before the transaction fail
[314]
Before, transaction starts
[318]
Before the transaction starts
[320]
And after the transaction completed
[324]
And after the transaction completed
[329]
Means before starting the transaction
[333]
And after the transaction completed
[336]
The sum of the money
[338]
Sum of money
[340]
Or the sum of the total money should be same
[348]
Should be same
[349]
How? I am telling you with a simple example
[352]
A transaction is t1
[354]
What are we doing in the transaction
[357]
From A account
[358]
In B account
[360]
Let's say we are transferring 1000 rupees
[363]
We are transferring from A account ot B account 1000 rupees
[365]
Initially in A
[367]
There are 2000 rupees
[368]
And in B there are 3000 rupees
[371]
In this database
[373]
The permanent database that we have
[375]
Over there the value of A is 2000 and of B 3000
[377]
So when the transaction will start
[379]
We have to transfer from A to B
[381]
so it is obvious
[382]
First of all we will have to read A
[384]
Meaning of reading A is
[386]
First of all I should know that
[389]
In A account
[390]
There are 1000/- or not
[392]
If in that there is no 1000/-
[394]
Then from where we will transfer
[395]
So first of all we did read of A
[397]
What is the meaning of reand of A
[399]
From database we will read
[401]
The value of A
[402]
What value will be read?
[402]
2000
[403]
Then we will do arithmetic operation
[407]
What is the arithmetic operation?
[408]
A=A-1000
[412]
Means we have done 1000/- minus from A
[415]
Who will execute this?
[416]
ALU
[418]
It is arithmetic operation so ALU will perform this
[420]
And we did write of A
[422]
write of A means
[426]
1000 value
[427]
It was 2000
[428]
so 2000-1000=1000
[431]
Where did this data get update?
[433]
In local memory
[435]
The shared memory we have
[436]
RAM is there, over there the value will be 1000
[439]
But still it is not updated in database
[441]
Now what we did
[442]
Read of B
[445]
Now we are reading account of B
[447]
That in B how many rupees are there?
[448]
In B there are 3000/-
[450]
So in that 3000 we have to add 1000
[455]
We have to add 1000/-
[456]
So after adding 1000/-
[458]
Write of B
[459]
So we have done write the value of B
[461]
We updated
[462]
What it is?
[463]
4000
[464]
We added 1000 in 3000
[466]
So what did happen?
[467]
4000
[468]
Now, where is this at present? In shared memory
[471]
The local memory is there
[472]
In RAM over there the value is 4000
[474]
Finally we write commit
[477]
Commit means
[478]
Whatever changes are there
[479]
Sift them permanently in database
[483]
So now in database what is the value of A now?
[486]
1000, and the value of B is 4000
[490]
So my transaction is completed
[493]
So over here what is the meaning of consistency?
[495]
Consistency is, when the transaction started
[498]
Before the transaction starts
[501]
What was the sum of the money?
[502]
What was the total?
[503]
2000+3000
[505]
5000
[506]
What is the total? 5000
[509]
And after the transaction completed
[512]
After the the transaction completed
[513]
When the transaction completed, then the value we updated of A and B
[516]
1000 and 4000
[518]
So what is its total?
[519]
5000
[520]
So the sum of the money should be
[522]
Same
[523]
So the sum of both is 5000 and 5000 is same
[527]
It is obvious
[528]
When you do transaction from ATM
[531]
Form ATM you have to withdraw 5000
[535]
And in your account there are 10000/-
[536]
so you swiped the card
[537]
Before starting the transaction there were 10000/-
[540]
You swiped the card
[541]
You entered the pin
[544]
Selected the language and did everything
[545]
And finally
[547]
Money commenced
[548]
Money came out
[549]
How much did it came? 5000
[551]
So 5000 are in your account
[553]
And 5000 cash is in your hand
[555]
So what is the total?
[556]
10000
[557]
But if the situation is that you entered the OTP
[562]
Sorry you entered the pin
[563]
You selected the language
[565]
And performed all the operation
[566]
But in last it came that money will be commencing from the machine
[571]
Noise came but no money came out from the machine
[574]
So if money did not came out from the machine and you get the message
[577]
That 5000 debited
[580]
5000 have been debited
[582]
Then how much money you have?
[583]
5000
[584]
And you did not get the cash
[586]
So it is obvious
[587]
Before starting there were 10000
[589]
Now how much you have? 5000
[591]
And where are the remaining 5000?
[594]
They are inconsistent, so in that case
[596]
Then the bank rollbacks and your transaction is performed successfully
[601]
So over here we are talking that only
[602]
Consistency means before the transaction starts
[605]
After the transaction completed
[607]
Sum of the money should be same
[610]
Third is isolation
[612]
Isolation property is again very important
[616]
What is the meaning of isolation property
[618]
We always talk about parallel transactions
[620]
Parallel transactions means
[622]
Where multiple transactions are running parallely
[626]
Like we did read of A
[627]
Then this came and did read of B
[629]
This came and did read of A
[631]
Means multiple transactions are running parallel
[634]
When multiple transactions run parallely
[637]
Means they are interfering with each other
[639]
Interfering with each other
[641]
Because CPU is switching
[643]
Sometimes it is executing over here
[644]
Then it is executing this
[646]
Then it is doing this
[647]
Then again it is doing this
[649]
In this way switching is done
[650]
so in this case
[652]
What does isolation property says
[654]
That Can I convert a parallel schedule into serial schedule
[660]
Not in real time just conceptually
[663]
What a parallel schedule can we convert into serial schedule?
[670]
Parallel schedule means
[672]
Let's say there is t1 and t2
[674]
So sometime t1 will be executed
[675]
Then t2 got executed
[676]
Then again T1 came
[678]
Then t2
[678]
Then t1 and then again t2
[679]
That is called parallel
[681]
So can I convert that first t1 will be executed
[684]
Then t2 will be executed
[686]
Or first t2 got completed
[689]
Then t1 was completed
[690]
Can I convert this into this?
[692]
Conceptually
[694]
On this there is a complete concept
[697]
Conflict serializability view serializability
[699]
When we will see that concept
[701]
Then it will be more clear
[702]
That what is the meaning of isolation
[704]
At present just remember that isolation property means
[708]
We are trying to convert a parallel schedule to serial schedule
[714]
This is the meaning
[715]
So what will we get from that?
[716]
If we convert a parallel in serial
[719]
Then what will happen?
[720]
Always serial schedule
[722]
Is consistent
[724]
So if serial schedule is always consistent
[726]
If I have converted a parallel schedule to serial
[730]
Then I can say that, that schedule is consistent
[735]
Yes, so that schedule will be consistent
[737]
Over there when we will see conflict serializability and view serializability
[741]
Then it will be more clear
[743]
Last is durability
[744]
So durability property means
[747]
That whatever changes you are doing
[749]
In database whatever changes we are doing
[752]
That all changes
[754]
Should be permanent
[756]
Means, Whatever you are changing
[758]
Let's see that we have done that example
[760]
When the transaction started
[763]
Then in A there were 2000 and in B 3000
[765]
When the transaction got completed
[767]
In a 1000
[768]
In B 4000
[769]
So we have updated
[772]
Is this update for 1 hour?
[774]
For 2 hours
[775]
For 4 hours
[776]
No
[777]
This update is not for all, means for whole lifetime
[781]
Until you don't update it again
[784]
It should not be like that
[785]
That when you switched on the system next day
[788]
Then the value of A 2000 and of B 3000
[791]
So what is the benefit
[792]
So that's why
[793]
Why do we save in hard disk
[795]
So that we get durability
[796]
Durability will be only got when we will save in hard disk
[801]
Like you have downloaded movie
[803]
Or you have taken a movie from your friend
[805]
And you have kept that movie in your drive
[807]
In C:, D: or E: any drive you have kept
[809]
Next day when you switched on your laptop
[812]
Or you switched on the system
[813]
Then that movie is not there in your laptop
[815]
Is it possible?
[816]
No
[817]
Because it is durable
[818]
Until you don't delete
[820]
Or hard drive doesn't crash
[822]
That is a different case
[823]
But durability means, the changes that are done
[825]
That are done
[826]
That is the meaning of durability
[829]
These are the 4 properties
[830]
Automaticity, Consistency, Isolation and Durability
[834]
In the database
[835]
Thank you