Transactions, Database Items, Read/Write Operations, and DBMS Buffers
Transactions, Database Items, Read/Write Operations, and DBMS Buffers
1. What is a Transaction?
A transaction is an executing program that performs a logical unit of work on a database.
It consists of one or more database operations.
Typical operations in a transaction include:
-
Insertion of new data
-
Deletion of existing data
-
Modification (Update) of data
-
Retrieval (Read) of data
These operations can be written:
-
Inside an application program, or
-
Interactively using SQL commands.
2. Transaction Boundaries
Transactions usually have explicit boundaries in programs:
All operations between these two statements are considered one transaction.
A single application program may contain multiple transactions, each separated by transaction boundaries.
3. Types of Transactions
Transactions are classified into two types:
| Type | Description |
|---|---|
| Read-only transaction | Only retrieves data; does not modify the database |
| Read-write transaction | Reads and updates the database |
Example:
-
Checking account balance → Read-only
-
Transferring money between accounts → Read-write
4. Database Representation in Transaction Processing
To simplify transaction processing concepts, the database is modeled as:
A collection of named data items
Each data item represents a unit of data.
Granularity of Data Items
The size of a data item is called granularity.
A data item could be:
-
A disk block
-
A database record
-
A field/attribute value
Examples:
| Granularity | Example |
|---|---|
| Large | Entire disk block |
| Medium | One record |
| Small | One attribute value |
Transaction processing works independently of granularity.
5. Basic Database Operations
Transactions access data using two fundamental operations.
1. read_item(X)
Reads the database item X into a program variable.
2. write_item(X)
Writes the value from the program variable X back to the database item X.
These two operations are the basic building blocks of transaction execution.
6. How read_item(X) Works
When a transaction executes:
The DBMS performs the following steps:
-
Find the disk block address containing item X.
-
Copy that disk block into main memory buffer (if not already there).
-
Copy X from the buffer to a program variable X.
So the flow is:
7. How write_item(X) Works
When executing:
The following steps occur:
-
Find the disk block containing X.
-
Copy the disk block into a memory buffer.
-
Copy the program variable X into the buffer.
-
Write the updated buffer back to disk.
Flow:
Step 4 actually updates the database permanently.
8. DBMS Buffers and Buffer Management
The DBMS uses buffers in main memory to temporarily store disk blocks.
A buffer:
-
Holds one disk block
-
Acts as a temporary working area
Why Buffers Are Used
Buffers help to:
-
Reduce disk I/O operations
-
Improve performance
-
Allow faster transaction processing
9. Delayed Disk Writing
Sometimes the DBMS does not immediately write modified buffers to disk.
Reasons:
-
More updates may occur soon
-
Writing immediately may reduce performance
The recovery manager decides when the updated buffer should be written to disk.
10. Buffer Replacement Policy
Main memory has limited buffers.
When all buffers are full and a new disk block must be loaded, the DBMS must choose which buffer to replace.
Common policy:
LRU (Least Recently Used)
The buffer that was used least recently is replaced.
If the buffer being replaced was modified, it must first be written back to disk.
11. Read Set and Write Set
Each transaction has:
Read Set
The set of all items the transaction reads.
Write Set
The set of all items the transaction updates.
Example:
Transaction T1 reads and writes X and Y.
12. Why These Concepts Matter
When multiple transactions run concurrently, they may:
-
Access the same data items
-
Update the same values
Without control, this may lead to:
-
Incorrect results
-
Data inconsistency
Therefore, concurrency control and recovery mechanisms focus on managing:
-
read_item -
write_item
operations safely.
13. Simple Conceptual Flow of Transaction Execution
Summary
Transactions interact with the database using read and write operations, while the DBMS buffers manage data movement between disk and memory to ensure efficient and correct execution of database operations.
Comments
Post a Comment