You ship a query on Monday. It runs in 2 ms. Six months later, the same query — same SQL, same indexes — takes 4 seconds. Nothing changed. Except one thing did: the table grew.
Welcome to the everyday problem Big O was invented to describe. This post is a practical, MySQL-flavoured tour of time complexity. We’ll keep the math light, the pictures clear, and we’ll finish with the exact algorithms your database uses to keep your queries fast (or slow).
What is Big O, really?
Forget seconds. Big O is not a unit of time. It’s a way of describing how the cost of an algorithm grows as the input grows. Specifically: if you double the data, does the work double? Stay the same? Quadruple? That shape is the algorithm’s complexity.
We call the input size n. A few shapes come up over
and over in real systems:
- O(1) — …