CREATE INDEX generates an auxiliary object that stores sorted references to the underlying table rows. Query planners use this structure to locate matching rows faster than a full table scan, especially for predicates, joins, and orderings on the indexed columns. Indexes speed reads but add overhead to INSERT, UPDATE, DELETE, and VACUUM operations because the index must stay in sync with the base table. Most databases allow additional options such as UNIQUE (to disallow duplicate key values), IF NOT EXISTS (to skip creation if the index already exists), index method selection (BTREE, HASH, GIN, GiST, FULLTEXT, CLUSTERED, etc.), partial indexes via WHERE predicates, index expressions on computed values, and included (non-key) columns for covering indexes. Locking behavior varies: PostgreSQL blocks writes during creation unless CONCURRENTLY is used, MySQL builds the index while blocking writes for the affected table engine, SQLite locks the database for the operation. Always weigh the read performance gain against write slowdowns and extra disk usage.
index_name
(identifier) - Name for the new indextable_name
(identifier) - Target table or materialized viewmethod
(enum) - Index type (BTREE, HASH, GIN, GiST, FULLTEXT, CLUSTERED, etc.)column_or_expression
(identifier or expression) - Key columns or expressions to indexASC
(DESC) - keyword|||Sort direction for each key columnNULLS FIRST
(LAST) - keyword|||Placement of NULL values (PostgreSQL, Oracle)INCLUDE
(keyword list) - Non-key columns stored in the leaf pages to make a covering index (PostgreSQL, SQL Server)WHERE partial_predicate
(boolean expression) - Limits index entries to rows matching the predicate (partial index)IF NOT EXISTS
(clause) - Skip creation if the index already existsUNIQUE
(clause) - Enforce uniqueness across key columnsALTER INDEX, DROP INDEX, UNIQUE constraint, ANALYZE, EXPLAIN, CLUSTER, CREATE UNIQUE INDEX, CREATE FULLTEXT INDEX
SQL-92 (basic), later extended per vendor
Create an index when a column or column group is heavily used in JOIN, WHERE, or ORDER BY clauses and the table has enough rows that scans are slow.
Yes. Every insert, update, or delete must also update each related index, so heavy write workloads can suffer. Measure the trade-off before adding indexes.
Run an EXPLAIN or EXPLAIN ANALYZE on the query. The execution plan will show index scans or seeks if the optimizer chooses the index.
Most databases support ALTER INDEX to rename, rebuild, or relocate indexes without dropping and recreating them.