0
0
SQLquery~5 mins

SELECT all columns in SQL - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: SELECT all columns
O(n)
Understanding Time Complexity

We want to understand how the time to run a query changes when we select all columns from a table.

Specifically, how does the work grow as the table gets bigger?

Scenario Under Consideration

Analyze the time complexity of the following SQL query.

SELECT *
FROM employees;

This query retrieves every column and every row from the employees table.

Identify Repeating Operations

Look for repeated actions in the query execution.

  • Primary operation: Reading each row from the employees table.
  • How many times: Once for every row in the table.
How Execution Grows With Input

As the number of rows grows, the work grows too.

Input Size (n)Approx. Operations
1010 reads of all columns
100100 reads of all columns
10001000 reads of all columns

Pattern observation: The work increases directly with the number of rows.

Final Time Complexity

Time Complexity: O(n)

This means the time to run the query grows in a straight line as the table gets bigger.

Common Mistake

[X] Wrong: "Selecting all columns is slower because of the * symbol itself."

[OK] Correct: The * just means all columns; the real time depends on how many rows and columns there are, not the symbol.

Interview Connect

Understanding how query time grows with table size helps you explain database performance clearly and confidently.

Self-Check

"What if we added a WHERE clause to filter rows? How would the time complexity change?"