Server configuration tuning in MySQL - Time & Space Complexity
When we tune server settings, we want to know how changes affect the speed of database operations.
We ask: How does the time to run queries grow as the server settings change?
Analyze the time complexity impact of this configuration change.
-- Example: Increasing the buffer pool size
SET GLOBAL innodb_buffer_pool_size = 1073741824; -- 1GB
-- Running a query that reads many rows
SELECT * FROM large_table WHERE some_column > 1000;
This code sets a larger memory buffer for InnoDB and runs a query scanning many rows.
Look at what repeats during query execution.
- Primary operation: Scanning rows in the table to find matches.
- How many times: Once per row scanned, which depends on table size.
As the table grows, the number of rows to scan grows too.
| Input Size (n rows) | 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 scanned.
Time Complexity: O(n)
This means the time to run the query grows in a straight line as the table gets bigger.
[X] Wrong: "Increasing buffer size makes query time constant no matter the table size."
[OK] Correct: Larger buffers help by caching data, but scanning still depends on how many rows exist.
Understanding how server settings affect query time helps you explain real-world database performance clearly and confidently.
"What if we add an index on some_column? How would the time complexity change?"