Major Storage Layouts

Introduction to Data Storage

Main MemoryCPU DieCPURegistersL1 CacheL2 CacheHard Disk

Alternative File organizations

  1. Heap Files
    • Random Order, Suitable when typical access is a file scan retrieving all records
    • data stored as multiple pages, header page and multiple data pages (subset of the table) connected in a heap (connected to each other through pointer)
    • As data gets inserted it gets put into empty pages
    • Advantages (effiecient)
      • For bulk loading data
      • for relatively small relations as indexing overheads are avoided
      • when queries that need to fetch proportion of stored records
    • Disadvantages (not efficient)
      • for selective queries
      • for sorting, may be time-consuming
        HeaderPageDataPageDataPageDataPageDataPageDataPageDataPageFull PagesPages withfree space
  2. Sorted Files
    • Best if records must be retrieved in some order or only a 'range' of records is needed
    • Based off of some attribute
  3. Indexes (B+ Tree indexes example)
    • Data structures to organize records via trees or hashing
    • - - -- - -- - -- - -- - -- - -- - -nonleafpagesleaf pagessorted bysearch keyindex entriesB+ Tree Indexes
    • Speeds up selection on the search key fields
    • Any subset of the fields of a relation can be the search key for an index on the relation
    • p0 k1 p1 k2 kn-m pn-1 kn pn+1 keysless than greater than key1 key1// less than key2
    • An index contains a collection of data entries and supports effecient retrieval of all data entries k* with a give value k
    • Pasted image 20260914191643.png|470

Major indexing schemes in database systems

Hash Based Indexing

Index Classification

Transactions/ACID Properties

Principles of Transactions : ACID Properties

A transaction is the DBMS's abstract view of a user program: a sequence of reads and writes
A user's program may carry out many operations on the data retrieved, but the DBMS is only concern about what data is red/written from/to the database

Concurrency Control in Database Systems

Concurrency Control

From above example

S1
T1 :  A = A + 100                 B = B - 100
T2 :                 A = 1.06 * A                B = 1.06 * B

This is ok but what about

S2
T1 : A = A + 100                               B = B-100  (This loses the
T2 :             A = 1.06 * A \\ B = 1.06 * B                bank money)
---------------------------------------------------------------------------
T1 : R(A) W(A)                          R(B) W(B)  
T2 :             R(A) W(A) \\ R(B) W(B)             

Conflict Serializable Schedules

Lock-Based Concurrency Control and Recovery from Failures

Lock-based concurrency control

Strict Two-phase Locking (Strict 2PL) Protocol:

T1 : S(A) R(A)       S(B)
T2 :            X(B) W(B)            X(C)
T3 :                       S(C) R(C)
T4 :                                 X(B)

T1T2T3T4BCB

T1 : S(A) R(A)       S(B)
T2 :            X(B) W(B)            X(C)
T3 :                       S(C) R(C)       X(A)
T4 :                                 X(B)

T1T2T3T4BCBADeadLock!!!!

Database Recovery

Fault -- causes --> Error -- results in --> Failure
Types of Failures