1
00:00:00,670 --> 00:00:01,110
Fine. Now,

2
00:00:01,110 --> 00:00:04,180
let's see the various states of a transaction.

3
00:00:04,610 --> 00:00:09,780
OK see let us assume that we are taking a single transaction single transaction.

4
00:00:09,790 --> 00:00:13,830
And as you know we can, we will have a set of operations on this transaction.

5
00:00:13,850 --> 00:00:14,120
Right.

6
00:00:14,420 --> 00:00:20,650
Let us assume it is something like, read of A, A equal to A
minus hundred.

7
00:00:21,020 --> 00:00:23,300
Then we have something like write of A.

8
00:00:23,330 --> 00:00:31,870
Then we have something called as read of B. B equal to B plus hundreds and a write of B which means

9
00:00:32,170 --> 00:00:36,090
I am transferring 50 dollars from A's account to B's account, right?

10
00:00:36,140 --> 00:00:36,620
Fine.

11
00:00:36,950 --> 00:00:40,500
And we have something called as Commit.

12
00:00:40,700 --> 00:00:42,780
Ok. We have something called called as Commit.

13
00:00:42,820 --> 00:00:47,830
Now what do we mean by this is, at the end of our transaction we generally do something.

14
00:00:47,830 --> 00:00:48,780
called as Commit.

15
00:00:48,900 --> 00:00:56,850
Which means we are going to say that whatever changes this transaction has made so far has been made

16
00:00:56,850 --> 00:00:59,590
as permanent inside the hard disk.

17
00:00:59,760 --> 00:01:00,370
Right?

18
00:01:00,450 --> 00:01:02,130
See what has happened here.

19
00:01:02,310 --> 00:01:05,410
We are, we are having a CPU fine.

20
00:01:05,460 --> 00:01:11,060
We are having registers it fine, and we are having RAM which is not important here.

21
00:01:11,070 --> 00:01:16,120
And also we're going to have something called as Hard Disk right? Now you because of the read of A

22
00:01:16,140 --> 00:01:23,040
We are moving the data from hard disk to register, fine? And using this we are going to update the value fine? And we're

23
00:01:23,040 --> 00:01:25,940
going to write this value inside the hard disk, right?

24
00:01:25,960 --> 00:01:31,470
So we have written the updated value of A inside the hard disk also we're going to do the same

25
00:01:31,470 --> 00:01:38,100
for B right? We're going to update the value of B in the hard disk, fine? Now though we have written both these

26
00:01:38,100 --> 00:01:45,970
values both the updated values inside the hard disk, these values are not permanent until we do something

27
00:01:45,970 --> 00:01:52,770
called as Commit, okay? Until we do something called as Commit which means though I am Writing these values inside

28
00:01:52,770 --> 00:01:59,310
inside the hard disk this is not permanent they are just temporary .OK? So what we do in general is at the

29
00:01:59,310 --> 00:02:04,600
end of the transaction we will do something called us commit which means we're going to say that whatever

30
00:02:04,770 --> 00:02:10,950
changes this transaction has made or whatever the effect this transaction has made that will be

31
00:02:10,950 --> 00:02:17,340
made as permanent, ok? That we do by using something called as commit, ok? This is a command. Fine.

32
00:02:17,670 --> 00:02:22,200
So now let's see what are the various stages of a particular transaction.

33
00:02:22,310 --> 00:02:23,000
Okay.

34
00:02:23,070 --> 00:02:28,110
First thing is the transaction will be in active state, Ok? It will be in active state let us assume

35
00:02:28,110 --> 00:02:34,650
that the transaction is, either, let us assume we have just now started the transaction okay? Which means

36
00:02:34,710 --> 00:02:38,810
we are over here, now the transaction is definitely in active state, OK?

37
00:02:39,050 --> 00:02:45,720
Now whether we are, whether we are, in this time or this time or this time or this time or this time

38
00:02:45,750 --> 00:02:53,290
so in whatever time period we are in, we can say that the transaction is in active stage. Right?

39
00:02:53,340 --> 00:02:59,550
Active state at this point of time the transaction is in Active state now let us assume, that all the steps of

40
00:02:59,550 --> 00:03:03,790
a particular transaction are over except, commit is not over.

41
00:03:03,790 --> 00:03:04,320
Ok?

42
00:03:04,340 --> 00:03:10,080
We have not committed a transaction see at this point of time all the operations of a particular

43
00:03:10,080 --> 00:03:14,510
transaction are over, but we didn't do something called as commit. Okay.

44
00:03:14,580 --> 00:03:20,730
Then we say that the transaction is partially complete, ok? The transaction is partially complete.

45
00:03:20,760 --> 00:03:25,580
So from active state we can go to something called us partially complete state.

46
00:03:26,150 --> 00:03:31,710
Ok? We can definitely do that we can go from active state to partially complete state, how? In case if we

47
00:03:31,710 --> 00:03:38,940
have done all the operations except commit. Ok, except commit fine. Now, from active state obviously our transaction

48
00:03:38,940 --> 00:03:44,790
can even fail. Right? Obviously it is possible our transaction can definitely, let us assume that transaction

49
00:03:44,790 --> 00:03:50,670
has failed over here. Ok it has failed over here in that case what we will do we will perform something

50
00:03:50,670 --> 00:03:54,220
called this rollback, what do you mean by rollback.

51
00:03:54,390 --> 00:03:59,750
We are going to undo the effects of this partially complete transaction.

52
00:04:00,110 --> 00:04:00,460
Okay.

53
00:04:00,610 --> 00:04:06,050
See because of the partially complete transaction what has happened A's value has been subtracted by hundreds.

54
00:04:06,380 --> 00:04:08,910
But we have not added hundred to B's value.

55
00:04:09,000 --> 00:04:10,480
That's what we have done till this point.

56
00:04:10,860 --> 00:04:13,410
No these are partial effects of this transaction.

57
00:04:13,410 --> 00:04:13,730
Why.

58
00:04:13,740 --> 00:04:15,690
Because the transaction is not yet complete.

59
00:04:16,020 --> 00:04:16,950
So what we will do.

60
00:04:16,950 --> 00:04:19,070
We will definitely perform the rollback.

61
00:04:19,080 --> 00:04:23,140
Which is as same as just aborting the transaction.

62
00:04:23,140 --> 00:04:23,450
Right?

63
00:04:23,490 --> 00:04:25,380
Which is our same as aborting the transaction.

64
00:04:25,680 --> 00:04:28,560
So our transaction can get failed anywhere over

65
00:04:28,570 --> 00:04:34,560
Here even our transaction can get failed over here, okay can definitely happen.

66
00:04:34,680 --> 00:04:40,500
Even if our transaction fails at this point of time which means whatever effect this transaction

67
00:04:40,500 --> 00:04:41,510
has made.

68
00:04:41,550 --> 00:04:47,870
They are just partial effects and so they has to be undone right? Which means..

69
00:04:47,920 --> 00:04:54,690
See let us assume the balance of A is thousand dollars fine? The balance of B was 900 dollars initially

70
00:04:54,790 --> 00:04:55,890
right initially.

71
00:04:55,900 --> 00:05:01,560
Now let us assume that we have completed the all the operations till this point but, we have not performed the

72
00:05:01,560 --> 00:05:02,750
commit, right?

73
00:05:02,790 --> 00:05:08,790
In the case what will happen A's value should have become 900 fine? And B's value should have become

74
00:05:08,790 --> 00:05:11,840
thousand, right? It should have become thousand fine.

75
00:05:11,850 --> 00:05:13,720
Now, we didn't commit the transaction.

76
00:05:13,740 --> 00:05:17,130
Let us assume, this transaction got failed at this point of time.

77
00:05:17,610 --> 00:05:22,820
Right, at this point of time. So, whatever changes we have made in the hard disk at this point of time they

78
00:05:22,820 --> 00:05:24,210
are not permanent. Right?

79
00:05:24,350 --> 00:05:26,760
They are just temporary because we have not done commit.

80
00:05:27,150 --> 00:05:32,350
So, they are just partial effects. So, these partial effects will be undone.

81
00:05:32,370 --> 00:05:33,490
How can we do that?

82
00:05:33,550 --> 00:05:38,930
Just restore to the previous value, when you when you did when you started the transaction right.

83
00:05:39,060 --> 00:05:43,630
In that case this will become thousand and this will become 900 right.

84
00:05:43,680 --> 00:05:46,700
This is what we mean by rollback. Right? Now,

85
00:05:46,700 --> 00:05:48,290
why did we do this rollback?

86
00:05:48,300 --> 00:05:53,220
Because, we have aborted the transaction. Right, we have aborted the transaction.

87
00:05:53,220 --> 00:05:57,890
If you want you can even write abort and rollback. If you want you can write this step.

88
00:05:57,960 --> 00:05:59,940
These are just names which we have created.

89
00:06:00,300 --> 00:06:01,270
Ok, fine.

90
00:06:01,470 --> 00:06:07,020
So, from active state a transaction go to either partially complete state which means from this state,

91
00:06:07,050 --> 00:06:13,840
it can either go to this state or it can even fail in between. Right? It can fail in between, fine and from

92
00:06:13,860 --> 00:06:16,880
partially complete state from this state,

93
00:06:16,920 --> 00:06:22,620
our transaction can either go to commit. In case, let us assume the transaction didn't fail and we have

94
00:06:22,620 --> 00:06:28,130
executed this command. In that case our transaction can go from partially complete state to committed

95
00:06:28,200 --> 00:06:32,780
state. Right? Where as in case if our transaction fails at this point of time,

96
00:06:32,820 --> 00:06:39,990
it is definitely possible, in that case it can go to failed state, right, failed state. Now, from partially

97
00:06:39,990 --> 00:06:44,360
complete step I can go to failed state as well as from active state I can go to failed state.

98
00:06:44,460 --> 00:06:45,590
I think you understood the point.

99
00:06:45,720 --> 00:06:46,310
Why?

100
00:06:46,350 --> 00:06:51,420
Because our transaction can get failed at this point, at this point, at this point or even it can get failed

101
00:06:51,420 --> 00:06:52,220
at this point.

102
00:06:52,400 --> 00:06:58,890
Okay, so from both these scenarios we can both to failed state, fine, from failed state obviously,

103
00:06:58,890 --> 00:07:02,280
there is no other way, we need to abort the transaction,  right.

104
00:07:02,520 --> 00:07:05,970
If you want to go write abort and rollback. Ok? If you want you can write it.

105
00:07:06,210 --> 00:07:10,500
So, whatever it is, in case a transaction fails we need to definitely abort it and we need

106
00:07:10,500 --> 00:07:11,610
to rollback.

107
00:07:11,610 --> 00:07:12,480
Fine.

108
00:07:12,510 --> 00:07:17,130
Now, from partially complete state our transaction can go to committed state. Right?

109
00:07:17,460 --> 00:07:18,900
It is definitely possible.

110
00:07:18,900 --> 00:07:22,040
So, these are the various states of a transaction.

111
00:07:22,070 --> 00:07:23,760
Ok, various states of a transaction.

112
00:07:23,850 --> 00:07:27,920
Let us assume that we have performed all the operations except commit.

113
00:07:27,990 --> 00:07:31,490
Then we say that the transaction is in partially complete state right.

114
00:07:31,680 --> 00:07:33,330
Now let us assume, we didn't

115
00:07:33,360 --> 00:07:34,350
perform commit,

116
00:07:34,350 --> 00:07:36,480
also we have not done all the operations.

117
00:07:36,480 --> 00:07:37,310
Let us assume we didn't

118
00:07:37,320 --> 00:07:40,700
perform this single operation we, our transaction is at this point of time.

119
00:07:40,920 --> 00:07:44,400
Ok, then we can say that the transaction is definitely in active state.

120
00:07:44,570 --> 00:07:44,980
Ok.

121
00:07:45,120 --> 00:07:48,350
Whereas in case if a transaction has performed all the operations except commit.

122
00:07:48,370 --> 00:07:53,430
Then we say it as part, the transaction is in partially complete state. Right? Whereas is in case if a transaction

123
00:07:53,430 --> 00:07:54,810
has failed in between,

124
00:07:54,810 --> 00:07:58,260
then we say that the transaction is in failed state. Then in that case,

125
00:07:58,260 --> 00:08:00,520
we need to definitely abort the transaction. Right?

126
00:08:00,840 --> 00:08:04,630
Whereas in case if we, our transaction has even executed this

127
00:08:04,660 --> 00:08:06,100
come commit command,

128
00:08:06,600 --> 00:08:09,990
then we say that the transaction is in committed state. Ok or

129
00:08:09,990 --> 00:08:12,130
we can say that the transaction is complete.

130
00:08:12,440 --> 00:08:12,840
Okay.

131
00:08:13,420 --> 00:08:19,020
So from partially complete state, we can go either committed state or we can go to failed state.

132
00:08:19,340 --> 00:08:19,950
Fine.

133
00:08:19,990 --> 00:08:21,360
See practically,

134
00:08:21,360 --> 00:08:25,420
we generally use commit at the end of a single transaction. Okay?

135
00:08:25,500 --> 00:08:30,550
The end of a transaction to make the, to make the changes in hard disk as permanent.

136
00:08:30,690 --> 00:08:32,610
Okay, that's why we use this commit statement.

137
00:08:33,000 --> 00:08:38,010
But theoretically, we can even use commit in between a transaction.

138
00:08:38,190 --> 00:08:39,720
Okay theoretically it is possible.

139
00:08:39,990 --> 00:08:44,150
So, let us assume that we have performed some operations and I have used commit, fine?

140
00:08:44,250 --> 00:08:50,220
And let us assume I'm still doing some other operations something like read of A, write of A

141
00:08:50,220 --> 00:08:52,080
or some ALU operation or something like this.

142
00:08:52,080 --> 00:08:57,630
Ok? I am doing some operations and at the end I am having commit as usual. Right? I am having commit

143
00:08:57,690 --> 00:08:58,470
as usual.

144
00:08:58,530 --> 00:09:03,960
Now let us assume that this transaction got failed somewhere over here, ok, anywhere over here. Now,

145
00:09:03,960 --> 00:09:07,320
let us assume that this transaction got failed somewhere over here. Right?

146
00:09:07,560 --> 00:09:09,090
In that case what will I do?

147
00:09:09,330 --> 00:09:11,900
I will definitely perform rollback, right.

148
00:09:12,110 --> 00:09:16,470
I will definitely perform rollback. Now, what will happen because of this rollback.

149
00:09:16,470 --> 00:09:18,930
See this point, because of this rollback.

150
00:09:18,930 --> 00:09:23,720
I will be heading to this position not this position.

151
00:09:23,730 --> 00:09:24,440
Why?

152
00:09:24,450 --> 00:09:31,890
Because whatever changes I have made till this point, till this point, has been made as permanent because

153
00:09:31,890 --> 00:09:33,490
of this commit statement.

154
00:09:33,500 --> 00:09:33,670
Right.

155
00:09:33,930 --> 00:09:35,320
Because of this comment statement.

156
00:09:35,360 --> 00:09:38,030
Now these changes cannot be undone.

157
00:09:38,030 --> 00:09:38,460
Why?

158
00:09:38,760 --> 00:09:42,240
Because we have made them as permanent because of this commit command.

159
00:09:42,450 --> 00:09:49,080
Right? Now in case if a transaction fails in between over here, either here or here or here or somewhere then,

160
00:09:49,080 --> 00:09:55,770
we will obviously perform rollback because this transaction got failed but because of that rollback, what

161
00:09:55,770 --> 00:10:01,620
we will be heading to this position, which means whatever changes we have made till this point has

162
00:10:01,620 --> 00:10:08,760
been made as permanent only the effects of these statements will only be the effects of these statements

163
00:10:08,790 --> 00:10:09,830
will be undone.

164
00:10:10,360 --> 00:10:12,050
Okay I think you're getting the point.

165
00:10:12,060 --> 00:10:16,470
Whatever changes we have made till this point has been made permanent because of this commit.

166
00:10:16,470 --> 00:10:21,770
Now in case if a transaction fails in between then we will be performing rollback and because of that

167
00:10:21,770 --> 00:10:25,090
roll back, only these effects will be undone.

168
00:10:25,230 --> 00:10:30,840
These effects cannot be undone because they have been already made as permanent because of this commit

169
00:10:30,860 --> 00:10:31,740
statement. Right?

170
00:10:31,860 --> 00:10:32,520
Fine.

171
00:10:32,550 --> 00:10:38,730
Now again, even let us assume this transaction has again performed commit, right, again performed commit.

172
00:10:38,940 --> 00:10:41,830
Now, in case if you are performing read of A, write of A

173
00:10:42,100 --> 00:10:44,320
and in case if a transaction got failed over

174
00:10:44,320 --> 00:10:46,830
here, we will obviously perform rollback.

175
00:10:46,930 --> 00:10:53,680
In that case, only these effects will be undone. Ok, which means so we whatever changes we have made

176
00:10:53,680 --> 00:10:55,720
till the point will be made as permanent.

177
00:10:55,750 --> 00:10:57,100
Because of this commit.

178
00:10:57,510 --> 00:10:59,170
Okay I think you're getting the point.

179
00:10:59,440 --> 00:11:05,580
This commit is actually used to say that ok, whatever I have till this point has to be made as

180
00:11:05,580 --> 00:11:10,270
permanent irrespective of whether the transaction fails hereafter or not.

181
00:11:10,360 --> 00:11:11,430
Okay fine.
