A database does a lot of things beyond just storing data/files! And it’s interesting to think about!
Firstly, it has an *index*, or maybe even many *indices* for each table. That means you take some property that you care about, sort it, and store that sorted version of the data separately, with a reference back to the rest of the stored data. This is super important because when data is sorted, you can really quickly find any specific value.
Here’s an example. Find the 3rd smallest number:
“`
853385090
379591565
306438809
663764153
482127012
137329860
203550656
114623436
972592136
394841008
709407303
546066368
214591581
717485067
560176143
“`
Now let me sort those numbers:
“`
114623436
137329860
203550656
214591581
306438809
379591565
394841008
482127012
546066368
560176143
663764153
709407303
717485067
853385090
972592136
“`
Much easier now, right? Computers agree with you. Generally, if you have twice as many numbers, it only needs one more step to find a sorted value, but twice as long to find a non-sorted value.
Database engines make use of tricks like this to make searching, filtering, finding data easier. They have many tables with relationships between them, which allows complex queries (“find me all employees who are sales people who have made more than $8m of sales in the last 12 months, excluding February”). They have logic to do transactions – either everything in my transaction updates, or nothing does. And that’s just scratching the surface- there’s so much engineering effort that goes into building production quality database systems.
Latest Answers