Assume there is a table T with one column only.
Assume that the "undo log" is a database file containing uncommitted
transactions, and that the "redo log" is a database file containing
both uncommitted and committed transactions that have not been yet applied to the datafiles.
At 8:00 A.M., Transaction 100 inserts rows with values 101, 102 and 103
into table T.
At 8:10 A.M., Transaction 100 is committed and the commit for
transaction 100 completes.
At 8:15 A.M., Transaction 200 updates row 101 to 201, 102 to 202
and 103 to 203.
At 8:20 A.M., Transaction 200 has not been committed and remains
in the undo log of the database.
At 8:25 A.M., Transaction 300 increments each row by 50,
changing row 201 to 251, 202 to 252, and 203 to 253.
At 8:30 A.M., Transaction 300 has not been committed and remains
in the undo log of the database.
At 8:35 A.M., The instance providing access to the database crashes.
At 8:40 A.M., The instance is restarted, and the database files are
opened as the instance is started:
The committed values in T are still 101, 102 and 103.
Since 201, 202, and 203, and 251, 252 and 253
are not committed, if they are written into the "redo
log" of the database, there is a need to "roll back"
the transactions AFTER the "redo log" is applied.
Since 201, 202, and 203, and 251, 252 and 253
are not committed, they are in the "undo log"
of the database.
The undo log of the database is used BOTH to (1) roll
back a transaction that is deliberately rolled
back in the memory structure of the database instance,
and also (2) during the instance recovery at 8:40 A.M.
At 8:41 A.M., The redo log has been applied, and the T table
contains values 251, 252 and 253 in the instance memory.
The undo log has not yet been applied.
At 8:42 A.M., The undo log is applied in the reverse order:
Uncommitted transaction 300 is undone, and
Uncommitted transaction 200 is undone.
Why are BOTH committed and uncommitted transactions written to the
redo log file? The reason for this is to provide point-in-time
recovery.
This means that the contents of the "redo log" file are NOT
transaction-consistent. For this reason, whenever the redo log
is used to apply committed transactions to the data files,
the "undo log" MUST ALSO be used to roll back uncommitted transactions.
Why are the transactions in the "undo log" rolled back in the
reverse order? The transaction 300 has added 50 to the existing value
of each column of each row. Therefore, if transaction 200 is rolled back
first, the values will change from 251, 252 and 253 to 201, 202 and
203. If transaction 300 were then rolled back last, the values
would be 151, 152 and 153 - that do not match the original
committed values.
REFERENCES:
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1670195800346464273