• Home
  • File Organizations

    In a Relational Database Management System (RDBMS), file organization refers to the way data is physically stored and organized on disk. There are several common file organization techniques used in RDBMS, including:


    1. Heap File Organization

    Heap file organization is a simple and straightforward method of storing data in a relational database management system (RDBMS). In a heap file, records are inserted into the file in no particular order, and they remain in the order they were inserted until they are deleted or modified.


    Here's an example to illustrate the heap file organization:

    Let's say we have a table called "Employees" with the following columns:

    - EmployeeID (integer)
    - Name (string)
    - Age (integer)
    - Department (string)


    Initially, the heap file is empty. When we insert records into the heap file, they are appended to the end of the file without any specific ordering.


    1. Inserting the first record:

    - EmployeeID: 101
    - Name: John
    - Age: 30
    - Department: Sales

    The record is inserted at the beginning of the file.


    2. Inserting the second record:

    - EmployeeID: 102
    - Name: Sarah
    - Age: 28
    - Department: HR

    The record is inserted after the first record.


    3. Inserting the third record:

    - EmployeeID: 103
    - Name: David
    - Age: 35
    - Department: Engineering

    The record is inserted after the second record.


    The heap file now contains the following records:

    EMPLOYEE ID NAME AGE DEPARTMENT
    101 John 30 Sales
    102 Sarah 28 HR
    103 David 35 Engineering

    As you can see, the records are stored in the order they were inserted, and there is no specific arrangement or sorting based on any column.


    One advantage of the heap file organization is that it allows for fast insertion of records since there is no need to maintain a specific order. However, retrieving specific records based on a certain criteria may require a full scan of the file, which can be inefficient for large databases.

    To improve the performance of record retrieval, additional indexing techniques such as B-trees or hash indexes can be used in conjunction with the heap file organization. These indexes provide faster access to specific records based on the indexed columns.

    2. Sorted File Organization:

    Sorted file organization is a method of storing data in a relational database management system (RDBMS) where records are stored in a sorted order based on one or more key columns. This allows for efficient searching, retrieval, and range-based operations on the data.


    Here's an example to illustrate sorted file organization:

    Let's consider a table called "Students" with the following columns:

    - StudentID (integer)
    - Name (string)
    - Age (integer)
    - GPA (float)

    We will sort the file based on the "StudentID" column in ascending order.


    1. Inserting the first record:

    - StudentID: 101
    - Name: John
    - Age: 20
    - GPA: 3.5

    Since the file is empty, the first record is inserted at the beginning.


    2. Inserting the second record:

    - StudentID: 102
    - Name: Sarah
    - Age: 19
    - GPA: 3.8

    The second record is inserted after the first record while maintaining the ascending order based on the "StudentID" column.


    3. Inserting the third record:

    - StudentID: 103
    - Name: David
    - Age: 21
    - GPA: 3.2

    The third record is inserted after the second record, also maintaining the ascending order based on the "StudentID" column.


    The sorted file now contains the following records:

    STUDENT ID NAME AGE GPA
    101 John 20 3.5
    102 Sarah 19 3.8
    103 David 21 3.2

    The records are stored in ascending order based on the "StudentID" column. This allows for efficient searching and range-based operations. For example, if we want to retrieve all students with an ID between 101 and 103, we can easily do so by performing a range scan on the sorted file.


    One advantage of sorted file organization is the improved performance for search and retrieval operations, especially when using range-based queries. However, it requires additional effort to maintain the sorted order when inserting or deleting records, as the file needs to be adjusted accordingly.

    To maintain the sorted order efficiently, additional indexing structures like B-trees or binary search trees are commonly used. These indexes provide fast access to specific records based on the indexed columns while minimizing the need for extensive file reorganization during insertions and deletions.

    3. Clustered File Organization:

    Clustered file organization, also known as clustered indexing or clustered tables, is a method of storing data in a relational database management system (RDBMS) where the physical order of the data in the file matches the order of the clustered index. In clustered file organization, the records are physically sorted based on one or more key columns, resulting in improved performance for range-based queries and data retrieval.


    Here's an example to illustrate clustered file organization:

    Consider a table called "Orders" with the following columns:

    - OrderID (integer)
    - CustomerID (integer)
    - OrderDate (date)
    - TotalAmount (float)

    We will cluster the file based on the "OrderDate" column, which means the records will be physically sorted in ascending order of the order dates.


    1. Inserting the first record:

    - OrderID: 1001
    - CustomerID: 101
    - OrderDate: 2023-01-15
    - TotalAmount: 250.00

    Since the file is empty, the first record is inserted at the beginning.


    2. Inserting the second record:

    - OrderID: 1002
    - CustomerID: 102
    - OrderDate: 2023-02-10
    - TotalAmount: 150.00

    The second record is inserted after the first record while maintaining the ascending order based on the "OrderDate" column.


    3. Inserting the third record:

    - OrderID: 1003
    - CustomerID: 103
    - OrderDate: 2023-02-28
    - TotalAmount: 300.00

    The third record is inserted after the second record, also maintaining the ascending order based on the "OrderDate" column.


    The clustered file now contains the following records:

    Order ID Customer ID Order DATE Total amount
    1001 101 2023-01-15 250.00
    1002 102 2023-02-10 150.00
    1003 103 2023-02-28 300.00

    As you can see, the records are stored in the physical order based on the "OrderDate" column. This organization allows for efficient range-based queries and retrieval of records within a specific date range. For example, retrieving all orders between 2023-01-01 and 2023-02-28 can be done by performing a sequential scan of the file starting from the first record with an order date on or after 2023-01-01 and ending at the last record with an order date on or before 2023-02-28.


    Clustered file organization is beneficial for queries that involve the clustering key, as it provides faster access to data in those scenarios. However, it may require additional effort to maintain the physical order when inserting or deleting records, as the file needs to be adjusted accordingly.

    4. Hash File Organization:

    Hash file organization is a method of storing data in a relational database management system (RDBMS) where records are distributed across multiple disk blocks based on a hash function. The hash function generates a hash value for each record, which is used to determine the disk block where the record will be stored. Hash file organization is primarily used for fast retrieval of individual records rather than range-based queries.


    Here's an example to illustrate hash file organization:

    Consider a table called "Employees" with the following columns:

    - EmployeeID (integer)
    - Name (string)
    - Age (integer)
    - Department (string)

    We will use the "EmployeeID" column as the hashing key.


    1. Inserting the first record:

    - EmployeeID: 101
    - Name: John
    - Age: 30
    - Department: Sales

    The hash function generates a hash value for the EmployeeID (101), which determines the disk block where the record will be stored.


    2. Inserting the second record:

    - EmployeeID: 102
    - Name: Sarah
    - Age: 28
    - Department: HR

    The hash function generates a hash value for the EmployeeID (102), which determines the disk block where the record will be stored. If the hash value for this record is the same as the first record, a collision occurs.


    3. Handling a collision:

    In case of a collision, various collision resolution techniques can be employed. One common technique is chaining, where each disk block has a linked list of records with the same hash value. In this example, let's assume that the second record with EmployeeID 102 is stored in the same disk block as the first record.

    The hash file now contains the following records:


    Disk Block 1:
    Employee ID NAME AGE Department
    101 John 30 sales
    102 Sarah 28 HR

    Disk Block 2:

    When retrieving a record, the hash function is applied to the key value, and the resulting hash value is used to determine the disk block where the record should be located. In this example, if we want to retrieve the record with EmployeeID 102, the hash function would be applied to 102, resulting in a hash value that points to Disk Block 1.

    Hash file organization provides fast retrieval of individual records since the hash function allows direct access to the disk block where the record should be stored. However, it may encounter collisions, which can impact performance and require additional steps for handling collisions, such as chaining or open addressing techniques.

    It's worth noting that hash file organization is not suitable for range-based queries or operations that involve searching for records based on a range of key values. In such cases, other file organization methods like sorted or clustered file organization would be more appropriate.

    5. Index-Sequential File Organization:

    Index-sequential file organization, also known as indexed sequential access method (ISAM), is a hybrid file organization method that combines the benefits of sequential and indexed file organizations. It uses an index structure to allow fast access to records while maintaining a sequential ordering of the data.


    Here's an example to illustrate index-sequential file organization:

    Consider a table called "Students" with the following columns:

    - StudentID (integer)
    - Name (string)
    - Age (integer)
    - GPA (float)

    We will use the "StudentID" column as the primary key.


    1. Initial table state:

    - StudentID: 101
    - Name: John
    - Age: 20
    - GPA: 3.5

    The first record is inserted into the file, and it becomes the initial data block.


    2. Inserting additional records:

    - StudentID: 102
    - Name: Sarah
    - Age: 19
    - GPA: 3.8

    The second record is inserted into the file, and it is placed after the first record in the data block.


    3. Inserting another record:

    - StudentID: 103
    - Name: David
    - Age: 21
    - GPA: 3.2

    The third record is inserted into the file. Since it has a higher StudentID value than the previous records, it is placed after them in the data block.


    At this point, the data blocks contain the following records:

    Data Block 1:
    STUDENT ID NAME AGE GPA
    101 John 20 3.5
    102 Sarah 19 3.8
    103 David 21 3.2

    To enable fast access to records based on the primary key, an index is created. The index structure consists of an index block that stores key-value pairs, where the key is the StudentID and the value is the address of the corresponding data block.


    Index Block:
    STUDENT ID DATA BLOCK ADDRESS
    101 Data block 1
    102 Data block 1
    103 Data block 1

    In the index block, each StudentID is associated with the address of the data block where its corresponding record is stored.


    When searching for a specific record, the index is used to locate the appropriate data block quickly. For example, if we want to retrieve the record with StudentID 102, we look up the index, find the associated data block address (Data Block 1), and directly access that block to retrieve the record.


    The index-sequential file organization provides efficient access to individual records through the index structure while maintaining a sequential ordering of the data blocks. This combination allows for fast retrieval of specific records as well as efficient range-based queries by traversing the sequential data blocks.

    Updates, such as insertions and deletions, require adjusting both the index and data blocks to maintain the sequential ordering and index integrity. This additional maintenance overhead is necessary to ensure the consistency and performance of the file organization.



    About the Author



    Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

    We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





     PreviousNext