Database Systems Lecture 4
DATABASE SYSTEMS
Introduction to Database Structure
Primary focus: How should a database system be structured to perform its tasks efficiently?
Data Storage as Text Files
Example: Creating a schema file named
schemes, where each line describes a database table.Example format in
schemes:majors#name#STR#responsible#STRstudents#name#STR#neptun#STR#major#STR
To store student data, a corresponding
studentsfile is created:Sample entries:
Gipsz Jakab#GIJKAAG#informaticsTeszt Elek#TEEKAAG#managerDóra Kalan#KADSAAT#teacher
Implementing Queries
Example query:
SELECT * FROM students WHERE neptun LIKE '%G' | gamfstudents
Database system process for executing the query:
Reads the
schemasfile to determine student attributes and their types.Checks if the specified conditions are applicable for students' relation.
Opens the
studentsfile and validates conditions for each row:If true, the line is copied into
gamfstudentsfile.Creates a new entry in the
schemasfile forgamfstudentswith a similar description asstudents.
Problems with Implementation
Key challenges faced when storing data:
Location of records on disk: Issues with modification (relocation, fragmentation).
Search Efficiency: Searches are sequential and costly.
Joining Tables: Joining tables using nested loops results in many unnecessary comparisons.
Buffering Issues: Inability to buffer frequently accessed data in central memory hampers efficiency.
Competition Management: Lack of competition management leads to file-level locking issues.
Reliability & Security: Overall poor reliability and security features.
Logical Structure of Database Management Systems (DBMS)
Overview of topics to be covered in the semester related to DBMS construction.
Components of a DBMS
Essential components that play critical roles in the functioning of a DBMS include:
Query Translator:
Analyzes and optimizes user/application queries.
Creates a modification query plan based on the query's structure.
Index, File, and Record Manager:
Manage files and record structures while handling indexing.
Execution Engine:
Requests smaller data pieces (e.g., records) from the resource manager for processing.
Buffer Manager:
Coordinates with the storage manager to ensure necessary data is in the buffer for quick access.
Resource Manager:
Knows data files, record formats, and index files.
Transaction Manager:
Receives and manages transactions, treating each as an atomic unit that is isolated from others.
Concurrency Manager:
Ensures operations have the same outcome as transactions under concurrent access, managing locks to prevent deadlocks.
Logging & Recovery Manager:
Manages logging of operations performed in transactions and restores consistency from logs if errors occur.
DDL Compiler:
Manages allocation and compilation of schema to structure data efficiently.
Managing Concurrency in a DBMS
Lock Tables:
Used for locking administration in central memory to prevent simultaneous access and maintain consistency.
Deadlock: Occurs when transactions are waiting on each other to release resources. Unlocking responsibilities fall on the transaction manager.
Memory Hierarchy in Data Storage
Cache:
Stores data and machine instructions, allowing data to be accessed approximately ten times faster than central memory.
Usually structured in minimum levels of two (on-board and level-2 cache).
Central Memory:
Functions as the practical working level with random access capability, typically with a reach time of around to s.
Virtual Memory:
Stores actively used program segments and data, primarily on disk, transferring data between disk and memory in block sizes, commonly ranging from 4 KB to 56 KB.
Secondary Storage:
Manages the flow of data blocks between disk and memory, often utilizing buffering to improve I/O operations.
Disk Access Efficiency
Read Access Latency:
Comprises three key elements:
Search Time: The time taken to move the reading head to the correct cylinder (typically 40-50 ms).
Rotation Delay: Time until the necessary sector rotates under the head (about 5 ms on average).
Transfer Time: Time taken for the sector to be read (< 0.5 ms).
Writing and Modifying Blocks:
Writing resembles the reading process,
Performance increases when using checksums over rotation checks for verification.
When modifying, processes consider reading time, processing in memory, and writing time.
Implementation Strategies for Optimizing Data Access
Data Organization in Cylinders:
Blocks accessed together are stored on the same cylinder, minimizing search times and improving efficiency.
Using Multiple Disks:
Reduces average access time proportionally to the number of disks if the system can handle the load effectively.
Disk Mirroring:
Multiple disks store the same data to increase fault tolerance, allowing simultaneous reads from any disk.
Disk Scheduling Algorithms:
The elevator algorithm scans the disk's surface from innermost to outermost cylinders, aiding in minimizing search times for I/O requests.
Early Scan and Large Scale Buffering:
Involves preloading required blocks into memory before they are needed to enhance accessibility.
Representation of Data within a Database
Representation follows the format specified by the
CREATE TABLEcommand, storing each row in a manner that attributes can be efficiently accessed.Common SQL Data Types:
INTEGER: 2 or 4 bytes, can be signed or unsigned.
FLOAT: 4 or 8 bytes in floating-point format.
CHAR(n): Fixed-length text with right padding.
VARCHAR(n): Variable-length text, requiring one additional byte to store length.
DATE: Stored as either 10-character text or numeric representation of days.
BOOLEAN: Typically represented in one full byte despite requiring one bit.
Record Management Techniques
Fixed Length Records:
Ideal for structured data types (e.g., INT or FLOAT) to improve access times by starting at divisible memory addresses.
Variable Length Records:
Handled with headers that detail field lengths and locations for efficient storage.
Spanned Records:
Allowed if the record exceeds block capacity or if significant empty space remains, requiring pointers for linkage.
Maintaining Data Integrity
Upon deletion, a tombstone is placed where the record existed, enabling subsequent checks and maintaining data integrity across references.
Modifications involve allocating space or adjusting pointer structures to reflect changes without disruption.
Pointer Management and Correction (Swizzling)
Addresses are corrected to reflect memory locations when data blocks are buffered. This involves recalibrating pointers based on the current memory address rather than secondary storage positions.
Conclusion
Efficient management of databases hinges on effective strategies for I/O operations, representation of data types, and concurrency control to ensure data consistency and performance optimization in a database system.