Ordered and unordered sequential files




















This means that half the file blocks must be read and rewritten after records are moved among them. For record deletion, the problem is less severe if deletion markers and periodic reorganization are used. One option for making insertion more efficient is to keep some unused space in each block for new records.

However, once this space is used up, the original problem resurfaces. Another frequently used method is to create a temporary unordered file called an overflow or transaction file. With this technique, the actual ordered file is called the main or master file.

New records are inserted at the end of the overflow file rather than in their correct position in the main file. Periodically, the overflow file is sorted and merged with the master file during file reorganization. Insertion becomes very efficient, but at the cost of increased complexity in the search algorithm.

The overflow file must be searched using a linear search if, after the binary search, the record is not found in the main file. For applications that do not require the most up-to-date information, overflow records can be ignored during a search.

Modifying a field value of a record depends on two factors: the search condition to locate the record and the field to be modified. If the search condition involves the ordering key field, we can locate the record using a binary search; otherwise we must do a linear search. A nonordering field can be modified by changing the record and rewriting it in the same physical location on disk—assuming fixed-length records. Modifying the ordering field means that the record can change its position in the file.

This requires deletion of the old record followed by insertion of the modified record. Reading the file records in order of the ordering field is quite efficient if we ignore the records in overflow, since the blocks can be read consecutively using double buffering. To include the records in overflow, we must merge them in their correct positions; in this case, first we can reorganize the file, and then read its blocks sequentially.

To reorganize the file, first we sort the records in the overflow file, and then merge them with the master file. The records marked for deletion are removed during the reorganization.

Table Ordered files are rarely used in database applications unless an additional access path, called a primary index , is used; this results in an indexed-sequential file. We discuss indexes in Chapter If the ordering attribute is not a key, the file is called a clustered file. Developed by Therithal info, Chennai. Toggle navigation BrainKart. Author : Ramez Elmasri, Shamkant B.

Navathe Posted On : Files of Ordered Records Sorted Files We can physically order the records of a file on disk based on the values of one of their fields—called the ordering field. This further improves the random access time on the ordering key field. Method of access , refers to the way in which records are accessed. Some organizations are more versatile than others. A file with an organization of Indexed or Relative may still have its records accessed sequentially; but records in a file with an organization of Sequential, cannot be accessed directly.

In a Sequential file the records are arranged serially, one after another, like cards in a dealing shoe. The only way to access records in a Sequential file, is serially. A program must start at the first record and read all the succeeding records until the required record is found or until the end of the file is reached.

Sequential files may be Ordered or Unordered these should be called Serial files. The ordering of the records in a file has a significant impact on the way in which it is processed and the processing that can be done on it. In an ordered file, the records are sequenced on some field in the record like StudentId or StudentName etc. In an unordered file, the records are not in any particular order.

It is easy to add records to an unordered Sequential file because we can simply add them to the end of the file by opening the file for EXTEND e. But it is not really possible to delete records from an unordered Sequential file.

And it is not feasible to update records in an unordered Sequential file. The animation below demonstrates how records are added to an unordered file. As in all the examples in this tutorial, the records to be added are contained in a transaction file.

The transaction file records are applied to the unordered file and the result is an unordered file that has all the transaction file records appended to the end of it. Although it is true that in standard COBOL, Sequential files cannot be deleted or updated "in situ", many vendors, including Microfocus, allow this for disk based files.

While it is easy to add records to an unordered Sequential file it is not really feasible to delete or update records in an unordered Sequential file. The only way to delete records from a Sequential file, is to create a new file which does not contain them; and the only way to update records in a Sequential file, is to create a new file which contains the updated records. Because both these operations rely on record matching, they do not work for unordered Sequential files.

Updates to Sequential files are normally done in batch mode. That is, all the updates are gathered together into a transaction file, and then applied to the target file in one go. The target file is often called the master file. There are few problems if we are just adding records to the end of a file, but if we want to update or delete records, then there must be some way of identifying the record we want to update or delete.

A "key field" is normally used to achieve this. A key field, is a field in the record whose value is unique to that record. For instance, in a student record, the StudentId is normally used as the key field.

Without a key field to identify the record we require, we cannot delete or update records. When we apply delete or update transaction records to a master file, we compare the key field in the transaction record with that in the master file record. If there is a match, we know we have to update or delete the master file record. If both files are ordered on the key field, then this record matching operation functions correctly, but if either the transaction or the master file is unordered, record matching cannot work.

Suppose we have an unordered transaction file and an unordered master file. The transaction file contains records which indicate which records in the master file we want to delete. To delete the records we need to create a new master file which does not contain the deleted records.

The animation below demonstrates what happens when we attempt to batch-delete records from an unordered Sequential file.

An ordered Sequential file, is a file ordered upon some key field. The ordering of the records in the file makes it possible to process an ordered file in ways that are not available to us with unordered files.

While it is not really possible to apply batch updates or deletes to an unordered file these are possible with ordered files. To add records to an ordered file a major consideration is to preserve the ordering.

This means that the record must be inserted into the file in the correct position. It can't just be added to the end of the file as it can with unordered files. As with all changes to ordered Sequential files we can't just insert the records into the existing file. To insert records into the file we have to create a new file that contains the inserted records.

The animation below demonstrates how records are inserted into an ordered Sequential file. The main processing loop from the animation is shown below. Examine the code in this program fragment and then attempt to answer the questions below.

The animation below demonstrates how to delete records from an ordered Sequential file. Updating a record requires a change to one or more of the fields in the record. Updates to Sequential files are usually collected together and applied to the file in one go - a batch. To update the records in an ordered Sequential file from an ordered batch of transaction records we have to create a new file that contains the updated records.

The animation below demonstrates how to batch-update records in an ordered Sequential files.



0コメント

  • 1000 / 1000