Oracle Database SQL Certified Associate
1 Introduction to SQL
1-1 Overview of SQL
1-2 History of SQL
1-3 SQL Standards
2 SQL Data Types
2-1 Numeric Data Types
2-2 Character Data Types
2-3 Date and Time Data Types
2-4 Large Object (LOB) Data Types
2-5 Miscellaneous Data Types
3 Creating and Managing Tables
3-1 Creating Tables
3-2 Modifying Tables
3-3 Dropping Tables
3-4 Table Constraints
3-5 Temporary Tables
4 Data Manipulation Language (DML)
4-1 Inserting Data
4-2 Updating Data
4-3 Deleting Data
4-4 Selecting Data
4-5 Using Subqueries
5 Data Control Language (DCL)
5-1 Granting Privileges
5-2 Revoking Privileges
6 Data Definition Language (DDL)
6-1 Creating Tables
6-2 Altering Tables
6-3 Dropping Tables
6-4 Creating Indexes
6-5 Dropping Indexes
6-6 Creating Views
6-7 Dropping Views
7 SQL Functions
7-1 Single-Row Functions
7-2 Aggregate Functions
7-3 Group Functions
7-4 Analytical Functions
8 Joins and Subqueries
8-1 Inner Joins
8-2 Outer Joins
8-3 Self-Joins
8-4 Cross Joins
8-5 Subqueries
9 Set Operators
9-1 UNION
9-2 UNION ALL
9-3 INTERSECT
9-4 MINUS
10 Grouping and Aggregation
10-1 GROUP BY Clause
10-2 HAVING Clause
10-3 ROLLUP and CUBE
10-4 GROUPING SETS
11 Transactions and Concurrency
11-1 Transaction Control Statements
11-2 Locking and Concurrency
11-3 Isolation Levels
12 Oracle SQL Developer
12-1 Overview of Oracle SQL Developer
12-2 Using SQL Worksheet
12-3 Managing Connections
12-4 Running Scripts
13 Advanced SQL Topics
13-1 Recursive Queries
13-2 Model Clause
13-3 PIVOT and UNPIVOT
13-4 Flashback Query
14 Performance Tuning
14-1 Query Optimization
14-2 Indexing Strategies
14-3 Analyzing Query Performance
15 Security and Auditing
15-1 User Management
15-2 Role Management
15-3 Auditing SQL Statements
16 Backup and Recovery
16-1 Backup Strategies
16-2 Recovery Strategies
16-3 Using RMAN
17 Oracle Database Architecture
17-1 Overview of Oracle Database Architecture
17-2 Memory Structures
17-3 Process Structures
17-4 Storage Structures
18 PLSQL Basics
18-1 Introduction to PLSQL
18-2 PLSQL Block Structure
18-3 Variables and Data Types
18-4 Control Structures
18-5 Exception Handling
19 Oracle SQL Certification Exam Preparation
19-1 Exam Objectives
19-2 Sample Questions
19-3 Practice Tests
19-4 Exam Tips
Indexing Strategies in Oracle SQL

Indexing Strategies in Oracle SQL

Key Concepts

Indexing strategies in Oracle SQL are techniques used to optimize query performance by creating and managing indexes on database tables. Understanding the following key concepts is essential for effective indexing:

1. Single Column Indexes

Single column indexes are created on a single column of a table. They are the simplest form of index and are useful for improving query performance on frequently queried columns.

Example:

Creating a single column index on the EmployeeID column of the Employees table:

CREATE INDEX idx_employee_id ON Employees(EmployeeID);

2. Composite Indexes

Composite indexes are created on multiple columns of a table. They are useful for queries that filter or sort on multiple columns.

Example:

Creating a composite index on the FirstName and LastName columns of the Employees table:

CREATE INDEX idx_employee_name ON Employees(FirstName, LastName);

3. Unique Indexes

Unique indexes ensure that the indexed columns contain unique values. They are often used to enforce primary key constraints.

Example:

Creating a unique index on the Email column of the Employees table:

CREATE UNIQUE INDEX idx_employee_email ON Employees(Email);

4. Function-Based Indexes

Function-based indexes are created on the result of a function applied to one or more columns. They are useful for queries that involve functions in the WHERE clause.

Example:

Creating a function-based index on the UPPER(LastName) column of the Employees table:

CREATE INDEX idx_employee_upper_lastname ON Employees(UPPER(LastName));

5. Bitmap Indexes

Bitmap indexes are useful for columns with low cardinality (few distinct values). They store bitmaps for each value and are efficient for read-heavy workloads.

Example:

Creating a bitmap index on the DepartmentID column of the Employees table:

CREATE BITMAP INDEX idx_employee_department ON Employees(DepartmentID);

6. Index Organized Tables (IOTs)

Index Organized Tables store data in an index structure, with the primary key as the clustering key. They are useful for tables where the primary key is frequently queried.

Example:

Creating an Index Organized Table for the Employees table:

CREATE TABLE Employees ( EmployeeID NUMBER PRIMARY KEY, FirstName VARCHAR2(50), LastName VARCHAR2(50) ) ORGANIZATION INDEX;

7. Partitioned Indexes

Partitioned indexes are created on partitioned tables. They can be local (partitioned the same way as the table) or global (spanning all partitions of the table).

Example:

Creating a local partitioned index on the EmployeeID column of a partitioned Employees table:

CREATE INDEX idx_employee_id ON Employees(EmployeeID) LOCAL;

8. Reverse Key Indexes

Reverse key indexes store the binary representation of the indexed column in reverse order. They are useful for spreading out index entries and reducing contention in high-concurrency environments.

Example:

Creating a reverse key index on the EmployeeID column of the Employees table:

CREATE INDEX idx_employee_id_reverse ON Employees(EmployeeID) REVERSE;

9. Index Compression

Index compression reduces the storage space required for indexes by eliminating duplicate column values. It is useful for large tables with many duplicate values.

Example:

Creating a compressed index on the DepartmentID column of the Employees table:

CREATE INDEX idx_employee_department ON Employees(DepartmentID) COMPRESS;

10. Index Maintenance

Index maintenance involves tasks such as rebuilding, reorganizing, and monitoring indexes to ensure optimal performance. Regular maintenance is crucial for large and frequently updated tables.

Example:

Rebuilding an index on the EmployeeID column of the Employees table:

ALTER INDEX idx_employee_id REBUILD;

11. Index Monitoring

Index monitoring involves tracking the usage and performance of indexes. Oracle provides views like DBA_INDEXES and V$OBJECT_USAGE to monitor index usage.

Example:

Monitoring the usage of an index on the EmployeeID column of the Employees table:

SELECT * FROM V$OBJECT_USAGE WHERE INDEX_NAME = 'IDX_EMPLOYEE_ID';

12. Index Partitioning Strategies

Index partitioning strategies involve creating indexes on partitioned tables. Local indexes are partitioned the same way as the table, while global indexes span all partitions of the table.

Example:

Creating a global partitioned index on the EmployeeID column of a partitioned Employees table:

CREATE INDEX idx_employee_id ON Employees(EmployeeID) GLOBAL;

13. Index Clustering Factor

The clustering factor of an index indicates how well the data is ordered according to the index. A low clustering factor indicates that the data is well-ordered, while a high clustering factor indicates scattered data.

Example:

Checking the clustering factor of an index on the EmployeeID column of the Employees table:

SELECT CLUSTERING_FACTOR FROM DBA_INDEXES WHERE INDEX_NAME = 'IDX_EMPLOYEE_ID';

14. Index Hints

Index hints allow you to suggest to the Oracle optimizer which indexes to use for a query. They are useful when the optimizer chooses a suboptimal execution plan.

Example:

Using an index hint to force the use of the idx_employee_id index in a query:

SELECT /*+ INDEX(Employees idx_employee_id) */ * FROM Employees WHERE EmployeeID = 123;