Glossary

Indexing

TL;DR

Indexing is a database optimization technique that creates data structures to enable faster data retrieval operations, significantly improving query performance at the cost of additional storage and maintenance overhead.


Concept

Indexing is a database optimization technique that creates auxiliary data structures to improve the speed of data retrieval operations on database tables. Similar to an index in a book, database indexes provide quick access to specific data without scanning the entire dataset.

Key features and concepts of indexing include:

  1. Data Structure: Indexes are organized data structures (such as B-trees, hash tables, or bitmap indexes) that store a subset of table data along with pointers to the actual data locations.

  2. Query Optimization: Indexes enable the database engine to locate rows quickly without scanning every row in a table, dramatically reducing query execution time.

  3. Key Columns: Indexes are created on one or more columns of a table, with the selected columns determining which queries can benefit from the index.

  4. Storage Overhead: Indexes require additional storage space and introduce maintenance overhead during data modification operations.

  5. Selectivity: The effectiveness of an index depends on the uniqueness of indexed values, with more selective indexes generally providing better performance.

Types of database indexes include:

  • Primary Index: Index on the primary key column(s) that uniquely identifies each row
  • Secondary Index: Index on non-primary key columns to improve query performance
  • Composite Index: Index on multiple columns combined
  • Unique Index: Index that enforces uniqueness constraint on indexed columns
  • Clustered Index: Index that determines the physical order of data in a table
  • Non-Clustered Index: Index that maintains logical ordering separate from physical data storage

Indexing strategies:

  • Covering Index: Index that includes all columns needed for a query, eliminating the need to access the table
  • Partial Index: Index that includes only rows meeting specific criteria
  • Full-Text Index: Specialized index for efficient text searching

Benefits of indexing include:

  • Improved Query Performance: Significantly faster data retrieval for indexed columns
  • Efficient Sorting: Faster ORDER BY operations on indexed columns
  • Quick Lookups: Rapid data access for WHERE clause conditions
  • Constraint Enforcement: Unique indexes enforce data integrity constraints

Drawbacks of indexing include:

  • Storage Overhead: Additional disk space required for index storage
  • Maintenance Cost: Slower INSERT, UPDATE, and DELETE operations due to index maintenance
  • Complexity: Need to carefully select appropriate indexes for optimal performance

Indexing is commonly used for:

  • Optimizing database query performance
  • Improving search functionality in applications
  • Enforcing data integrity constraints
  • Accelerating reporting and analytics queries
  • Supporting efficient JOIN operations

Organizations implement indexing strategies to improve application performance, reduce database load, and enhance user experience. Proper index design is crucial for database performance and requires balancing query performance gains against storage and maintenance costs.

Related words: CDN Caching Concurrency