Index make searching faster and you don;t need to do verification for each record.
Types of Index
1. Simple Index: on one Column
2. Composite Index: multiple Column
3. Unique Index :No duplication in column
4. Reverse Index: start work in reverse order
5. Function-based Index:you need to perform some function like salary commission of an employee,or average of student marks
6. Bitmap Index:works on less number of values,like status-->active/inactive,gender-->male/female
2. Need of Index
When we run query (Select marks from student where marks <33);
OR
When we run query (Select sale from employee where salary <5000);
Frequently verifying conditions
Frequently assessing
Assessing multiple records
Index
Index maintains column data in ascending order
It also maintain addresses
Why we use Index
Decrease no. of verification
Save time
Better performance
3. Example
Roll_No Name Marks Address Roll_No Marks
1 Ali 45 BWP 5 22
2 Usama 87 LHR 6 30
3 Usman 48 BWP 1 45
4 Ahmed 64 BWP 3 48
5 Amir 22 BWP 4 64
6 Umer 30 LHR 2 87
4. Types of Index
Simple Index
Composite Index
Unique Index
Reversing Index
Function based Index
Bitmap Index
Simple Index
Index create on single column. e.g., sale from employee table ,marks from
student table, etc.
Query
Create INDEX IDX_SALARY on employee(sale);
Searching in index, not table
5. Composite Index
Index creates on multiple columns on any table.
Query
Create INDEX idx_s.no_rollNo on students(s.no, rollNo);
Unique Index
Index creates on columns ----- no duplication
Query
Create UNIQUE INDEX idx_mobileNo on customers_dtls(mobile);
Reversing Index
Want to search data frequently looking for highest value.
Normally List values------- beginning, Highest value---------ending
Its searching is fast because its work in reversing order.
Based on Binary tree.------ right to left in b.tree.
Create INDEX idx_sales_amt on sales(sales_amt) REVERSE;
6. Function based index
Work on function based.
Suppose I have a table of employee, and have a column of emp_id,salary,commission
Query
Select e_id,sal(0.100*sal) from emp
Create Index idx_sal on emp(sal(0.100*sal))init cap(ename);
Bitmap index
Bits --------- 0,1
Less number of values in columns
E.g.,
status--active/inactive,
Gender--male/female
Query
Create bitmap Index id_gender on customer(gender);
Note:
All index created based on the binary tree index.