0
0
Supabasecloud~10 mins

Database indexes in Supabase - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Database indexes
Start Query
Check for Index
Yes / No?
Use Index
Return Results
End
When a query runs, the database checks if an index exists for the search. If yes, it uses the index to find data fast. If no, it scans the whole table, which is slower.
Execution Sample
Supabase
CREATE INDEX idx_user_email ON users(email);

SELECT * FROM users WHERE email = 'a@b.com';
Create an index on the email column, then query users by email using the index for faster lookup.
Process Table
StepActionIndex Exists?Query MethodResult
1Start query to find user by emailN/AN/AQuery initiated
2Check if index on email existsYesUse IndexIndex used to find matching rows
3Retrieve matching rows using indexYesUse IndexRows found quickly
4Return results to clientYesUse IndexResults returned
5End queryN/AN/AQuery complete
💡 Query ends after using index to quickly find matching rows instead of scanning whole table
Status Tracker
VariableStartAfter Step 2After Step 3Final
index_existsundefinedtruetruetrue
query_methodundefineduse indexuse indexuse index
rows_found0055
Key Moments - 2 Insights
Why does the database check for an index before searching?
The database checks for an index (see Step 2 in execution_table) to decide if it can find data quickly. Using an index avoids scanning the whole table, making queries faster.
What happens if there is no index on the searched column?
If no index exists, the database does a full table scan (not shown here). This means it looks at every row, which is slower than using an index.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the query method used at Step 3?
AFull table scan
BNo method
CUse index
DCache lookup
💡 Hint
Check the 'Query Method' column at Step 3 in the execution_table
At which step does the database confirm the index exists?
AStep 2
BStep 4
CStep 1
DStep 5
💡 Hint
Look at the 'Index Exists?' column in the execution_table
If the index did not exist, how would the 'query_method' variable change after Step 2?
AIt would be 'use index'
BIt would be 'full table scan'
CIt would be 'no method'
DIt would be 'cache lookup'
💡 Hint
Refer to variable_tracker for 'query_method' and think about what happens if no index is found
Concept Snapshot
Database indexes speed up data searches.
Create an index on columns you query often.
Database checks for index before searching.
If index exists, it uses it to find rows fast.
Without index, it scans the whole table slowly.
Full Transcript
When you run a query to find data, the database first checks if there is an index on the column you are searching. If an index exists, it uses that index to quickly find matching rows instead of scanning the entire table. This makes queries much faster. For example, creating an index on the email column lets the database find users by email quickly. If no index exists, the database must scan every row, which takes more time. This process is shown step-by-step in the execution table and variable tracker.