Types of databases (relational, NoSQL, object-oriented) in DBMS Theory - Time & Space Complexity
We want to understand how the time it takes to work with different types of databases changes as the amount of data grows.
How does the database type affect the speed of finding or saving data?
Analyze the time complexity of basic data retrieval in different database types.
-- Relational database query example
SELECT * FROM users WHERE id = 123;
-- NoSQL document lookup example
db.users.find({"id": 123});
-- Object-oriented database object retrieval
user = db.getObjectById("User", 123);
These commands get a user record by ID from three database types.
Look at what happens when the database searches for the user.
- Primary operation: Searching through data entries to find a match.
- How many times: Depends on data size; the database may check many records.
As the number of users grows, the search work changes differently for each database type.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Few checks, very fast |
| 100 | More checks, still quick |
| 1000 | Many checks, time grows |
Relational databases often use indexes to keep search fast even as data grows. NoSQL may vary by type; some are very fast for certain queries. Object-oriented databases depend on how objects are linked.
Time Complexity: O(log n)
This means that as data grows, the time to find a record grows slowly, usually doubling data size adds only a little more time.
[X] Wrong: "All databases take the same time to find data regardless of type."
[OK] Correct: Different database types organize data differently, so their search speeds change differently as data grows.
Knowing how database types affect search speed helps you explain your choices clearly and shows you understand how data size impacts performance.
"What if we added an index to the NoSQL database? How would the time complexity change?"
Practice
Solution
Step 1: Understand database types
Relational databases organize data in tables with rows and columns.Step 2: Identify query language
They use SQL (Structured Query Language) to manage and query data.Final Answer:
Relational database -> Option DQuick Check:
Tables + SQL = Relational database [OK]
- Confusing NoSQL with relational because both store data
- Thinking object-oriented databases use SQL
- Assuming graph databases are relational
Solution
Step 1: Recall NoSQL database features
NoSQL databases store data flexibly, often as documents or key-value pairs.Step 2: Eliminate incorrect options
They do not require fixed schemas or only tables, and do not rely solely on SQL.Final Answer:
Stores flexible data like documents or key-value pairs -> Option AQuick Check:
No fixed schema + flexible data = NoSQL [OK]
- Thinking NoSQL uses only tables
- Confusing object-oriented with NoSQL
- Assuming NoSQL requires SQL queries
Data is stored as objects with properties and methods, similar to programming languages.Solution
Step 1: Analyze data storage style
The data is stored as objects with properties and methods, matching programming language objects.Step 2: Match to database type
Object-oriented databases store data as objects, unlike relational or NoSQL databases.Final Answer:
Object-oriented database -> Option CQuick Check:
Objects with methods = Object-oriented database [OK]
- Confusing object-oriented with NoSQL
- Thinking relational databases store objects
- Assuming hierarchical is object-oriented
NoSQL databases always use SQL queries to retrieve data.Solution
Step 1: Understand NoSQL query methods
NoSQL databases typically use query methods other than SQL, like JSON queries or key-value lookups.Step 2: Identify the error
The statement wrongly claims NoSQL always uses SQL, which is false.Final Answer:
NoSQL databases do not use SQL queries -> Option BQuick Check:
NoSQL ≠ SQL queries [OK]
- Believing NoSQL uses SQL
- Confusing NoSQL with relational
- Thinking NoSQL stores only tables
Solution
Step 1: Analyze data needs
Flexible fields suggest NoSQL for schema flexibility; complex objects with methods suggest object-oriented database.Step 2: Choose suitable combination
Using both NoSQL and object-oriented databases fits the requirements best.Final Answer:
A NoSQL database for flexible data and an object-oriented database for complex objects -> Option AQuick Check:
Flexible + complex objects = NoSQL + object-oriented [OK]
- Choosing only relational database ignoring flexibility
- Using only NoSQL and ignoring object methods
- Assuming object-oriented alone handles flexible fields
Ready to prove it?
Pass the test and this pattern moves unknown
