MySQL vs PostgreSQL vs SQLite - Performance Comparison
When using different database systems like MySQL, PostgreSQL, and SQLite, it helps to understand how their operations grow as data grows.
We want to see how the time to run queries changes when the amount of data increases.
Analyze the time complexity of a simple SELECT query on a table in each database.
SELECT * FROM users WHERE age > 30;
This query fetches all users older than 30 from a users table.
Look at what repeats when the query runs.
- Primary operation: Scanning rows to check the age condition.
- How many times: Once for each row in the users table.
As the number of users grows, the database checks more rows.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 row checks |
| 100 | 100 row checks |
| 1000 | 1000 row checks |
Pattern observation: The work grows directly with the number of rows.
Time Complexity: O(n)
This means the time to run the query grows in a straight line as the table gets bigger.
[X] Wrong: "All databases handle queries with the same speed no matter the data size."
[OK] Correct: Different databases use different methods like indexes that change how fast queries run as data grows.
Understanding how query time grows helps you explain database choices and performance in real projects.
What if we add an index on the age column? How would the time complexity change?