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:

BEGIN TRANSACTION Database operations END TRANSACTION

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:

TypeDescription
Read-only transactionOnly retrieves data; does not modify the database
Read-write transactionReads 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:

GranularityExample
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:

read_item(X)

The DBMS performs the following steps:

  1. Find the disk block address containing item X.

  2. Copy that disk block into main memory buffer (if not already there).

  3. Copy X from the buffer to a program variable X.

So the flow is:

Disk → Main Memory Buffer → Program Variable

7. How write_item(X) Works

When executing:

write_item(X)

The following steps occur:

  1. Find the disk block containing X.

  2. Copy the disk block into a memory buffer.

  3. Copy the program variable X into the buffer.

  4. Write the updated buffer back to disk.

Flow:

Program VariableMemory BufferDisk

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.

Read Set = {X, Y} Write Set = {X, 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

TransactionRead/Write Operations ↓ DBMS Buffers (Main Memory) ↓ Disk Storage (Database)

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

Popular posts from this blog

Database Management Systems DBMS PCCST402 Semester 4 KTU CS 2024 Scheme

Data Models, Schemas and Instances

Introduction to Database Management System -DBMS