0% found this document useful (0 votes)
10 views

File Organization and Indexing

The document discusses different types of files and file organization methods. It describes physical files, logical files, special character files, fixed and variable length record files. It also covers different file organization techniques like sequential, serial, indexed sequential access method and random access files. The document then discusses database indexing and different types of indexes like primary, secondary and clustering indexes.

Uploaded by

Rashmi Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

File Organization and Indexing

The document discusses different types of files and file organization methods. It describes physical files, logical files, special character files, fixed and variable length record files. It also covers different file organization techniques like sequential, serial, indexed sequential access method and random access files. The document then discusses database indexing and different types of indexes like primary, secondary and clustering indexes.

Uploaded by

Rashmi Das
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

File Organization

File system:

File: File is a collection of records which are logically related to any object. Record value can
in any form like data.

For eg. : Each students records which having values of Roll no, Name, Class.

For arranging data we use file.

For eg.: files of bank‟s customer, files of department, files of stack records etc. Files are
recorded on secondary storage such as magnetic disks, magnetic tables and optical disks.
Types of files:

- Physical file:
o Physical file concern with actual data that is stored.
o It stores description about how the data is to be represented.
- Logical file-
o Logical file: do not contain data.
o They contain a description of records that are found in one or
more physical files.
o A logical file is a view or representation of one or more physical files.
- Special character file:
o At the time of file creation we insert some special characters in file.
o For eg: Control + z for end of a file which having ASCII value 26

According to records types of files:

1. Fixed length record file


2. Variable length record file

1. Fixed length record file:

Every record in this file has same size(in bytes). Record


having value set, in the fixed length record file, memory
block are assign in same size. For eg., if the size for a record
is assigned 30 bytes to each then records in this type are
stored like as below,

Advantage: records are stored in fixed distance of memory


block, so fast searching for a particular record is done.
Disadvantage: Memory blocks are unnecessarily used when
record size is small as compared to assigned memory block. This
useless memory block increases size of file.
2. Variable length record file:

Every record in this file has variable size (in bytes). Memory
block are assign for a file records are in variable size. Different
records in the file have different sizes. As per size of records
value, memory blocks are used.
Advantage: Memory used efficiently for storing record.
Whatever exact size of record that much size of memory block
occupies in memory in this kind of records. Because of less
memory they can move, save or transfer from one location to
other in fast manner.

Disadvantage: Access for record is slower as compared to fixed


length record file due to varying size of a record.
File organization:

File organization refers to the logical relationships among various records that
constitute the file, particularly with respect to the means of identification and
access to any specific record. In short, storing the files in certain order is called
file organization.

Types of file organization:

1. Sequential file organization: Sequential file organization is easiest


method. In this method files are stored one after the other in a sequential
manner.

This method is also called as Pile or sorted file.

This method is fast & efficient for huge amount of data.

Sorted file is inefficient as it takes time & space for sorting records.

2. Serial file organization: Serial file organization is also called as heap


file. In this method, records are inserted at the end of file into the data
blocks. There is no requirement of sorting data.

When huge amount of data is to be inserted at a time in a organization,


that time this method is suitable.
Accessing of data is slower as compared to sorted file method.

3. Index Sequential Access Method (ISAM): ISAM method is advanced


sequential file organization. In this method, index value is generated and
mapped with every record. Using that index, accessing of record is
done.

4. Random access / Direct access file organization: In this file


organization records are stored randomly but accessed directly. To
access a file stored randomly, a record key is used to determine where a
record is stored on the storage media. Magnetic and optical disks allow
data to be stored and accessed randomly.

DBMS - Indexing
Indexing is a data structure technique to efficiently retrieve records from the database files
based on some attributes on which the indexing has been done. Indexing in database systems is
similar to what we see in books.

We can define index as a schema object that contains an entry for each value that appears in the
indexed column(s) of the table or cluster and provides direct, fast access to rows. Oracle
Database supports several types of index: Normal indexes. (By default, Oracle Database creates
B-tree indexes.)

Indexing is defined based on its indexing attributes. Indexing can be of the following types −

● Primary Index − Primary index is defined on an ordered data file. The data file is
ordered on a key field. The key field is generally the primary key of the relation.

● Secondary Index − Secondary index may be generated from a field which is a candidate
key and has a unique value in every record, or a non-key with duplicate values.

● Clustering Index − Clustering index is defined on an ordered data file. The data file is
ordered on a non-key field.
Ordered Indexing is of two types −

● Dense Index
● Sparse Index
Dense Index
In dense index, there is an index record for every search key value in the database. This makes
searching faster but requires more space to store index records itself. Index records contain
search key value and a pointer to the actual record on the disk.

Sparse Index
In sparse index, index records are not created for every search key. An index record here
contains a search key and an actual pointer to the data on the disk. To search a record, we first
proceed by index record and reach at the actual location of the data. If the data we are looking
for is not where we directly reach by following the index, then the system starts sequential
search until the desired data is found.

Multilevel Index
Index records comprise search-key values and data pointers. Multilevel index is stored on the
disk along with the actual database files. As the size of the database grows, so does the size of
the indices. There is an immense need to keep the index records in the main memory so as to
speed up the search operations. If single-level index is used, then a large size index cannot be
kept in memory which leads to multiple disk accesses.
Multi-level Index helps in breaking down the index into several smaller indices in order to make
the outermost level so small that it can be saved in a single disk block, which can easily be
accommodated anywhere in the main memory.

Secondary Index in DBMS


The secondary Index in DBMS can be generated by a field which has a unique value for each
record, and it should be a candidate key. It is also known as a non-clustering index.

This two-level database indexing technique is used to reduce the mapping size of the first level.
For the first level, a large range of numbers is selected because of this; the mapping size always
remains small.

Secondary Index Example


Let’s understand secondary indexing with a database index example:

In a bank account database, data is stored sequentially by acc_no; you may want to find all
accounts in of a specific branch of ABC bank.

Here, you can have a secondary index in DBMS for every search-key. Index record is a record
point to a bucket that contains pointers to all the records with their specific search-key value.
CREATE AN INDEX

Syntax
The syntax for creating an index in Oracle/PLSQL is:

CREATE [UNIQUE] INDEX index_name

ON table_name (column1, column2, ... column_n);

UNIQUE

It indicates that the combination of values in the indexed columns must be unique.

index_name

The name to assign to the index.

table_name

The name of the table in which to create the index.

column1, column2, ... column_n

The columns to use in the index.


Example
Let's look at an example of how to create an index in Oracle/PLSQL.
For example:

CREATE INDEX supplier_idx

ON supplier (supplier_name);

CREATE A FUNCTION-BASED INDEX


In Oracle, you are not restricted to creating indexes on only columns. You can create
function-based indexes.

Syntax
The syntax for creating a function-based index in Oracle/PLSQL is:

CREATE [UNIQUE] INDEX index_name

ON table_name (function1, function2, ... function_n)

UNIQUE

It indicates that the combination of values in the indexed columns must be unique.

index_name

The name to assign to the index.

table_name

The name of the table in which to create the index.

function1, function2, ... function_n

The functions to use in the index.

Example
Let's look at an example of how to create a function-based index in Oracle/PLSQL.
For example:
CREATE INDEX supplier_idx

ON supplier (UPPER(supplier_name));

In this example, we've created an index based on the uppercase evaluation of the supplier_name
field.

RENAME AN INDEX

Syntax
The syntax for renaming an index in Oracle/PLSQL is:

ALTER INDEX index_name

RENAME TO new_index_name;

index_name

The name of the index that you wish to rename.

new_index_name

The new name to assign to the index.

Example
Let's look at an example of how to rename an index in Oracle/PLSQL.
For example:

ALTER INDEX supplier_idx

RENAME TO supplier_index_name;

In this example, we're renaming the index called supplier_idx to supplier_index_name.

Confirming Indexes:-

The USER_INDEXES data dictionary view contains the name of the index and its uniqueness.
The USER_IND_COLUMNS view contains the index name, the table name, and the column
name.

Syntax:-

SELECT ic.index_name, ic.column_name, ic.column_position col_pos, ix.uniqueness

FROM user_indexes ix, user_ind_columns ic

WHERE ic.index_name=ix.index_name

AND ic.table=’table name’;

Example;

SELECT ic.index_name, ic.column_name, ic.column_position col_pos, ix.uniqueness

FROM user_indexes ix, user_ind_columns ic

WHERE ic.index_name=ix.index_name

AND ic.table=EMP_2016’;

Output:-

COLUMN_NAM COL_POS
INDEX_NAME E UNIQUENESS

EMP_EMPNO_PK EMP_NO 1 UNIQUE

EMP_ENAME_ID
X ENAME 1 NONUNIQUE

DROP AN INDEX

Syntax
The syntax for dropping an index in Oracle/PLSQL is:
DROP INDEX index_name;

index_name

The name of the index to drop.

Example
Let's look at an example of how to drop an index in Oracle/PLSQL.
For example:

DROP INDEX supplier_idx;

In this example, we're dropping an index called supplier_idx.

Note: To drop an index, you must be the owner of the index or have the DROP ANY INDEX
privilege.

You might also like