DBMS 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Storage Strategies in Databases

Efficient storage strategies optimize data retrieval and minimize storage space in databases.
Key strategies include indices, B-trees, and hashing.

1. Indices

Indices are data structures that improve query performance by reducing the search space for
specific rows.

Features:

 Serve as lookup tables to map search keys to corresponding rows in a table.


 Enhance query speed, especially for large datasets.
 Typically used in columns that are queried frequently or used for sorting.

Common Index Types:

 Primary Index: Built on a primary key.


 Secondary Index: Built on non-primary key attributes.
 Clustered Index: Rows are stored in the same order as the index.
 Non-Clustered Index: The index contains pointers to the rows in the table.

Trade-offs:

 Advantages: Speeds up search and retrieval.


 Disadvantages: Increases storage space and update time.

2. B-Trees

B-trees are balanced tree data structures widely used for indexing and organizing data in
databases.

Structure:

 Hierarchical with nodes containing keys and pointers to child nodes.


 Keeps data sorted and allows searches, sequential access, insertions, and deletions in
logarithmic time.

Properties:

 Each node has a maximum and minimum number of children, ensuring balance.
 Keys in each node are in sorted order.
 Leaf nodes are at the same level, ensuring uniform depth.
Use Case:

 Ideal for range queries and situations where data must be accessed sequentially or
randomly.

Trade-offs:

 Advantages: Efficient for read-heavy workloads.


 Disadvantages: Slightly slower for writes due to rebalancing.

3. Hashing

Hashing involves transforming a search key into a unique location (bucket) in memory using
a hash function.

Structure:

 Hash table consists of buckets, each capable of storing one or more records.
 The hash function computes the bucket index from the search key.

Types of Hashing:

 Static Hashing: Fixed number of buckets.


 Dynamic Hashing: Buckets are dynamically allocated based on data volume.

Properties:

 Directly maps keys to their storage location.


 Suitable for exact-match queries (e.g., WHERE id = 100).

Trade-offs:

 Advantages: Fast for point lookups.


 Disadvantages:
o Not suitable for range queries.
o May face collisions (two keys mapping to the same bucket).

Comparison of Strategies

Feature Indices B-Trees Hashing


Efficiency Fast search Logarithmic operations Constant-time lookup
Use Case General querying Range queries Exact-match queries
Storage Medium to high Medium Low to medium
Drawback Space overhead Write overhead Poor for range queries
Each strategy serves specific needs, and their combination often optimizes database
performance.

You might also like