Why database structure determines app performance in No-Code - Performance Analysis
How a database is organized affects how fast an app can find and use data.
We want to know how the structure impacts the time it takes to get results as data grows.
Analyze the time complexity of searching data in two database structures.
// Structure A: Flat list of records
// Structure B: Indexed records by key
function findRecordFlat(list, key) {
for (const record of list) {
if (record.key == key) return record
}
return null
}
function findRecordIndexed(index, key) {
return index[key] || null
}
This code shows two ways to find a record: scanning a list vs using an index.
Look at what repeats when searching for data.
- Primary operation: Checking each record one by one in the flat list.
- How many times: Up to all records in the list (depends on list size).
- Primary operation: Direct lookup in the index (no loop).
- How many times: Just once, no matter how big the data is.
As data grows, the time to find a record changes differently for each structure.
| Input Size (n) | Flat List Checks | Indexed Lookups |
|---|---|---|
| 10 | Up to 10 checks | 1 lookup |
| 100 | Up to 100 checks | 1 lookup |
| 1000 | Up to 1000 checks | 1 lookup |
Pattern observation: Flat list time grows with data size; indexed lookup time stays the same.
Time Complexity: O(n) for flat list, O(1) for indexed lookup
This means scanning a list takes longer as data grows, but using an index finds data quickly no matter the size.
[X] Wrong: "All database searches take the same time regardless of structure."
[OK] Correct: Searching a flat list checks many items, so time grows with data size. Indexes let you jump directly to data, keeping search time short.
Understanding how database structure affects speed helps you explain why some apps feel faster and how to design better systems.
"What if the index was built on multiple keys instead of one? How would that affect the time complexity of searching?"