Part 3 of 5 · 1 min read
Sorted files
Records kept in order by one chosen column, speeding up range queries.
Think of a phone book, kept alphabetically sorted by last name. Finding everyone between "Rao" and "Reddy" means reading one contiguous section, not searching the whole book.
In plain words: a sorted file keeps records physically ordered by one chosen column. This makes a range query on that column fast, since matching rows sit together contiguously. Inserting a new record is slower, since it must go in the correct sorted position, often requiring existing records to shift.
A worked example. A sorted-by-placed_on orders file answers "every order from March" quickly, reading one contiguous block of rows. Inserting a new order from an earlier date requires shifting later rows to make room in the correct sorted position.
The key lines. No SQL; again a storage-engine detail.
Sorted file
A sorted file keeps records physically ordered by one column, speeding up range queries on that column, at the cost of slower inserts that must maintain the sorted order.
Example: a file sorted by placed_on answers a date-range query by reading one contiguous section, but inserting an out-of-order date requires shifting existing records.