- Normal Index
- Function-Based Index
- Bitmap Index
- Unique Index, subject to compatibility with other indexes
1. Create an EMPLOYEE Table
First, create an EMPLOYEE table with four columns.CREATE TABLE EMPLOYEE
(
EMP_ID NUMBER,
EMP_NAME VARCHAR2(50),
DEPT_ID NUMBER,
SALARY NUMBER
);
Insert sample records:
INSERT INTO EMPLOYEE VALUES
(101, 'Ravi', 10, 30000);
INSERT INTO EMPLOYEE VALUES
(102, 'Kumar', 20, 40000);
INSERT INTO EMPLOYEE VALUES
(103, 'Sita', 10, 50000);
COMMIT;
2. Example 1: Normal Index and Function-Based Index on the Same Column
First, create a Normal Index on EMP_NAME.Normal Index
CREATE INDEX IDX_EMP_NAME
ON EMPLOYEE(EMP_NAME);
Now create a Function-Based Index on the same column.
Function-Based Index
CREATE INDEX IDX_EMP_UPPER_NAME
ON EMPLOYEE(UPPER(EMP_NAME));
What Is the Difference?
| Index | Indexed Expression |
|---|---|
| IDX_EMP_NAME | EMP_NAME |
| IDX_EMP_UPPER_NAME | UPPER(EMP_NAME) |
Query 1: Using Normal Index
SELECT *
FROM EMPLOYEE
WHERE EMP_NAME = 'Ravi';
Oracle may use:
IDX_EMP_NAME
Query 2: Using Function-Based Index
SELECT *
FROM EMPLOYEE
WHERE UPPER(EMP_NAME) = 'RAVI';
Oracle may use:
IDX_EMP_UPPER_NAME
The optimizer decides which access path is most efficient.
3. Example 2: B-tree Index and Bitmap Index on the Same Column
Oracle also supports different index types on the same column, subject to applicable restrictions. First, create a B-tree Index.B-tree Index
CREATE INDEX IDX_EMP_DEPT
ON EMPLOYEE(DEPT_ID);
Now create a Bitmap Index on the same column.
Bitmap Index
CREATE BITMAP INDEX IDX_EMP_DEPT_BITMAP
ON EMPLOYEE(DEPT_ID);
B-tree Index vs Bitmap Index
| B-tree Index | Bitmap Index |
|---|---|
| Uses a B-tree structure | Uses bitmap structures |
| Good for high-cardinality columns | Often useful for low-cardinality columns |
| Common in OLTP systems | Common in Data Warehousing |
| Generally suitable for frequent DML | Can be problematic with frequent concurrent DML |
4. Example 3: Can We Create Two Normal Indexes on the Same Column?
Suppose we create the following index.CREATE INDEX IDX_EMP_NAME1
ON EMPLOYEE(EMP_NAME);
Now try creating another Normal Index on the same column.
CREATE INDEX IDX_EMP_NAME2
ON EMPLOYEE(EMP_NAME);
Oracle generally returns the following error:
ORA-01408: such column list already indexed
Why?
Because both indexes have the same column definition and indexing characteristics.
Creating an identical index does not provide additional benefits.
5. Visual Representation: Multiple Indexes on the Same Column
Let's understand this with a simple diagram.EMP_NAME COLUMN
Normal Index
EMP_NAME
Function-Based Index
UPPER(EMP_NAME)
Two different index definitions based on the same table column.
6. How to Check Multiple Indexes on the Same Column?
We can use Oracle data dictionary views to check the indexes created on a table.Query 1: Check Index Columns
SELECT
INDEX_NAME,
TABLE_NAME,
COLUMN_NAME,
COLUMN_POSITION
FROM USER_IND_COLUMNS
WHERE TABLE_NAME = 'EMPLOYEE'
ORDER BY COLUMN_NAME, INDEX_NAME;
This query displays the indexed columns and their positions.
Query 2: Check Index Types
SELECT
INDEX_NAME,
INDEX_TYPE,
UNIQUENESS
FROM USER_INDEXES
WHERE TABLE_NAME = 'EMPLOYEE';
This query displays the index type and uniqueness information.
Query 3: Check Function-Based Index Expressions
SELECT
INDEX_NAME,
COLUMN_EXPRESSION
FROM USER_IND_EXPRESSIONS
WHERE TABLE_NAME = 'EMPLOYEE';
This query helps us identify expressions used in Function-Based Indexes.
7. Important Oracle Interview Questions
Q1. Can we create multiple indexes on the same column in Oracle?
Answer: Yes. Oracle supports multiple indexes on the same column when their definitions differ appropriately.
Q2. Can we create a Normal Index and Function-Based Index on the same column?
Answer: Yes.
CREATE INDEX IDX1
ON EMPLOYEE(EMP_NAME);
CREATE INDEX IDX2
ON EMPLOYEE(UPPER(EMP_NAME));
Q3. Can we create a B-tree Index and Bitmap Index on the same column?
Answer: Oracle supports different index types on the same column, subject to applicable restrictions.
Q4. Can we create two identical Normal Indexes on the same column?
Answer: Generally, no. Oracle raises ORA-01408 when the same column list is already indexed.
Q5. Is it recommended to create multiple indexes on the same column?
Answer: Not usually. Create multiple indexes only when there is a specific performance requirement.
8. Easy Way to Remember
| Scenario | Allowed? |
|---|---|
| Normal + Function-Based Index | Yes |
| B-tree + Bitmap Index | Yes, subject to restrictions |
| Two identical Normal Indexes | Generally No |
| Different expressions on same column | Yes |