0
0
Supabasecloud~5 mins

Creating tables via SQL editor in Supabase - Performance & Efficiency

Choose your learning style9 modes available
Time Complexity: Creating tables via SQL editor
O(n)
Understanding Time Complexity

When creating tables using the SQL editor in Supabase, it's important to understand how the time it takes grows as you add more tables.

We want to know how the number of tables affects the total time to create them all.

Scenario Under Consideration

Analyze the time complexity of creating multiple tables one after another.


-- Create first table
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL
);

-- Create second table
CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  title TEXT NOT NULL
);

-- Create third table
CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id),
  product_id INTEGER REFERENCES products(id)
);

This sequence creates three tables with some references between them.

Identify Repeating Operations

Each CREATE TABLE statement is an operation sent to the database.

  • Primary operation: Executing a CREATE TABLE SQL command.
  • How many times: Once per table you want to create.
How Execution Grows With Input

Each new table adds one more CREATE TABLE command to run.

Input Size (n)Approx. API Calls/Operations
1010 create table commands
100100 create table commands
10001000 create table commands

Pattern observation: The number of commands grows directly with the number of tables.

Final Time Complexity

Time Complexity: O(n)

This means the time to create tables grows in a straight line as you add more tables.

Common Mistake

[X] Wrong: "Creating multiple tables at once takes the same time as creating one table."

[OK] Correct: Each table creation is a separate command that takes time, so more tables mean more commands and more time.

Interview Connect

Understanding how operations add up helps you plan database setup and shows you think about efficiency in real projects.

Self-Check

"What if we combined multiple table creations into a single transaction? How would the time complexity change?"