Creating tables via SQL editor in Supabase - Performance & Efficiency
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.
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.
Each CREATE TABLE statement is an operation sent to the database.
- Primary operation: Executing a
CREATE TABLESQL command. - How many times: Once per table you want to create.
Each new table adds one more CREATE TABLE command to run.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 create table commands |
| 100 | 100 create table commands |
| 1000 | 1000 create table commands |
Pattern observation: The number of commands grows directly with the number of tables.
Time Complexity: O(n)
This means the time to create tables grows in a straight line as you add more tables.
[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.
Understanding how operations add up helps you plan database setup and shows you think about efficiency in real projects.
"What if we combined multiple table creations into a single transaction? How would the time complexity change?"