🗄️ Database Design / Normalization
Beginner
What is an index in a database?
Answer
A database index is a data structure (typically a B-tree) that provides fast lookup of rows based on the values of one or more columns, similar to a book's index. Without an index, the database must scan every row (full table scan). With an index, it navigates the B-tree to find matching rows in O(log n) time. Create: CREATE INDEX idx_email ON users(email). Trade-offs: indexes speed up SELECT queries but slow down INSERT, UPDATE, DELETE (the index must be maintained). Always index: primary keys (automatic), foreign keys, and frequently filtered/sorted columns.
Previous
What is Boyce-Codd Normal Form (BCNF)?
Next
What is the difference between a clustered and non-clustered index?