File Organization and Indexing
File Organization and Indexing
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 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
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.
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.
Sorted file is inefficient as it takes time & space for sorting records.
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.
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.
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:
UNIQUE
It indicates that the combination of values in the indexed columns must be unique.
index_name
table_name
ON supplier (supplier_name);
Syntax
The syntax for creating a function-based index in Oracle/PLSQL is:
UNIQUE
It indicates that the combination of values in the indexed columns must be unique.
index_name
table_name
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:
RENAME TO new_index_name;
index_name
new_index_name
Example
Let's look at an example of how to rename an index in Oracle/PLSQL.
For example:
RENAME 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:-
WHERE ic.index_name=ix.index_name
Example;
WHERE ic.index_name=ix.index_name
AND ic.table=EMP_2016’;
Output:-
COLUMN_NAM COL_POS
INDEX_NAME E UNIQUENESS
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
Example
Let's look at an example of how to drop an index in Oracle/PLSQL.
For example:
Note: To drop an index, you must be the owner of the index or have the DROP ANY INDEX
privilege.