An INDEX is a physical or logical structure that stores the values of specified column(s) in a way that makes searches, joins, and filtering operations faster. Instead of scanning every row, the database engine navigates the index (often a B-tree or hash) to locate matching records quickly. Indexes can enforce uniqueness, support primary and foreign keys, and improve ORDER BY performance. However, they consume storage and slow down INSERT, UPDATE, and DELETE operations because the index itself must be updated. Proper indexing requires balancing read speed with write overhead and choosing the right index type for each workload.
index_name
(identifier) - Name of the index to create or droptable_name
(identifier) - Table on which the index is builtcolumn_list
(list) - One or more columns to include in the index, with optional sort orderindex_type
(keyword) - Optional engine-specific clause (e.g., USING HASH, USING GIN) specifying index methodCREATE INDEX, UNIQUE, PRIMARY KEY, FOREIGN KEY, CLUSTERED INDEX, NONCLUSTERED INDEX, ANALYZE, EXPLAIN
SQL-92
A clustered index defines the physical order of rows on disk (only one allowed per table in most engines). A nonclustered index stores a separate structure that points back to the table, allowing multiple per table.
Many databases support functional or expression indexes, letting you index computed values like LOWER(email) for case-insensitive searches. Syntax varies by dialect.
Run an EXPLAIN or EXPLAIN ANALYZE plan before the query. The output shows whether the planner chooses an index scan and which index it uses.
Indexing foreign key columns usually speeds up joins and deletes, but small tables may not benefit. Benchmark before adding unnecessary indexes.