An index is an additional lookup structure maintained by the database, often a B-tree. It can help locate matching rows or support an order, but uses storage and adds work to writes. The optimizer decides whether to use it; an index does not guarantee speed.
CREATE INDEX books_shelf_pages_idx ON books (shelf_id, pages);
EXPLAIN QUERY PLAN SELECT title FROM books WHERE shelf_id = 1 AND pages > 90;
A composite index is ordered by its leading column then later columns. The leading shelf_id can make this index useful for shelf-based queries; queries only on pages may need another strategy, depending on optimizer and data. EXPLAIN QUERY PLAN reports SQLite’s chosen approach, whose wording and plan can vary by version and statistics. Measure representative workloads before adding indexes or denormalizing. If duplicate summary data is stored for speed, define how writes keep it consistent and how discrepancies are repaired.