Question Most Common
What are the indexes, advantages + disadvantages?
A
Anonymous
December 15, 2025
129
Answer
An index is a separate structure the database keeps next to a table so it can find rows by a column value without scanning the whole table. Queries that filter, join or sort on an indexed column read far fewer pages, so SELECT, JOIN, WHERE and ORDER BY get faster. A unique index also enforces that no two rows share the same value.
Single-column index
Created on one column. It helps when you often search, filter or sort by that column.
CREATE INDEX idx_product_id ON Sales (product_id);
This creates an index named idx_product_id on the product_id column of the Sales table.
Multi-column index
Created on two or more columns. It helps when queries filter or join on those columns together.
CREATE INDEX idx_product_quantity ON Sales (product_id, quantity);
With this index the database can filter or join on product_id and quantity together without a full scan.
Advantages
- Faster SELECT queries
- Cheaper sorting and filtering
- Faster joins
- Fewer full table scans
Disadvantages
- Slower INSERT, UPDATE and DELETE, because every index on the table has to be updated as well
- Extra storage
- Maintenance overhead
- Too many indexes slow writes down more than they speed reads up
JuniorSeniorDatabase