Indexes

Indexing  a table is an access strategy that is a way to sort and search records in the table. Indexes  are essential to improve the speed with which the records can be located and retrieved from a table.
An Index is an ordered list of the contents of a column, or group of columns of a table.
Indexing involves forming a two dimensional matrix completely independent of the table on which the index is being created.

When data is inserted in the table the oracle engine inserts the data value in the index. For every data value held in the index the oracle engine inserts a unique rowid value. This is done for every data value inserted into the index, without exception. This ROWID  indicates exactly where the record is stored in the table.

Addressfield in the index:-
The address field of an index Is called ROWID. ROWID is an internal generated and maintained binary value which identifies a record. The information in the ROWID column provides Oracle engine the location of the table and a specific record in the oracle database.
The ROWID format is as follows:-
BBBBBBB.RRRR.FFFF
Where
BBBBBBB   à Data Blocks
RRRR          à Records.
FFFF           à Unique Field number
Duplicate Or Unique Index
Oracle follows the two types of indexes. These are

Instances when the Oracle engine uses an index for data extraction:-

Instances when the Oracle engine does not use an index for data extraction:-

Each time a record is inserted into the table oracle locates free space in the blocks in the data files. The oracle engine then inserts a record in all the indexes associated with the table. The index entries are sorted in the ascending order as well. If too many indexes were created the oracle engine would take longer to insert a record in the table since index processing must be done after every record.
Thus though indexes spends up data retrieval the inserts would be slow. A balance must be maintained such that only the columns that are frequently used for retrieval are indexed.
An index can be created one or more columns. Based on the number of columns included in the index . an index can be

Simple Index
An index created on single column of a table is called simple index.
Syntax:- Create index indexname on tablename(columnname);
Ex:-     1)   create index myindex on vision(eno);
2)   Select * from vision where eno=300;
3)   select * from vision order by eno;
4)   Select * from vision where sal>2000; 
( in this example index will not applicable because condition is not on
indexed column)

Composite Index:- An index created on more than one column it is called composite index . That allows duplicate values.
Syntax:- create index indexname on tablename(columnname,columname,……);
Ex:-     1)   create index myindex1 on vision (eno,sal);
            2)   Select * from vision where eno=300;
             3)   select * from vision order by eno;
             4)   Select * from vision where sal>2000;

Unique Index :- A unique index can also be created on one or more columns. If an index is created on a single column it is called simple unique index. An index is created on more that one column is called composite unique index.
Syntax:-   1) create unique index myindex2 on stock1(icode);
                        (This will show error because duplicates are existed)
            2) create unique index myindex2 on vision(eno);
            3) create unique index myindex3 on vision(eno,sal);
           4) select * from vision where eno=300;
            5) select * from vision where sal>2000;
Note:- Once the index is created on a table the same table should not use for creating index again.

For
Online Classes

Contact Us: +919885348743