0
0
Supabasecloud~20 mins

Query optimization with EXPLAIN in Supabase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
EXPLAIN Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding EXPLAIN output for a simple SELECT

You run the following query on a Supabase PostgreSQL database:

SELECT * FROM users WHERE age > 30;

Using EXPLAIN on this query, which part of the output tells you if an index is used?

AThe 'Sort' keyword indicates an index is used.
BThe 'Aggregate' keyword indicates an index is used.
CThe 'Seq Scan' keyword indicates an index is used.
DThe 'Index Scan' keyword indicates an index is used.
Attempts:
2 left
💡 Hint

Look for keywords that describe how the database reads rows.

service_behavior
intermediate
2:00remaining
Effect of adding an index on EXPLAIN output

You have a table orders with millions of rows. Initially, you run:

EXPLAIN SELECT * FROM orders WHERE customer_id = 123;

The output shows a 'Seq Scan'. After adding an index on customer_id, you run the same EXPLAIN again. What change do you expect in the output?

AThe output will show 'Aggregate' because of the index.
BThe output will show 'Index Scan' indicating the index is used.
CThe output will show 'Hash Join' instead of 'Seq Scan'.
DThe output will still show 'Seq Scan' because indexes don't affect EXPLAIN.
Attempts:
2 left
💡 Hint

Think about how indexes help find rows faster.

Architecture
advanced
2:30remaining
Choosing the best index type for query optimization

You want to optimize a query filtering by a text column email in a Supabase PostgreSQL database. The query is:

SELECT * FROM users WHERE email LIKE 'john%';

Which index type is best to speed up this query and why?

AA B-tree index, because it supports prefix matching with LIKE.
BA Hash index, because it is faster for all LIKE queries.
CA GIN index, because it supports full-text search and LIKE efficiently.
DNo index helps with LIKE queries.
Attempts:
2 left
💡 Hint

Consider how the pattern 'john%' works with different index types.

security
advanced
2:30remaining
Security implications of EXPLAIN in production

Allowing users to run EXPLAIN on queries in a production Supabase database can expose sensitive information. What is a key security risk of unrestricted EXPLAIN access?

AUsers can see the exact data stored in tables.
BEXPLAIN can modify data if misused.
CUsers can learn the database schema and query patterns, aiding attacks.
DEXPLAIN disables database encryption.
Attempts:
2 left
💡 Hint

Think about what EXPLAIN reveals about the database structure.

Best Practice
expert
3:00remaining
Interpreting EXPLAIN ANALYZE for query tuning

You run this command in Supabase:

EXPLAIN ANALYZE SELECT * FROM products WHERE price > 100;

The output shows:

Seq Scan on products  (cost=0.00..1000.00 rows=500 width=50) (actual time=0.01..500.00 rows=1000 loops=1)

What does the large difference between estimated rows (500) and actual rows (1000) suggest?

AThe statistics are outdated or inaccurate, causing poor estimates.
BThe query plan is accurate and needs no change.
CThe index is being used correctly.
DThe query is using a join instead of a scan.
Attempts:
2 left
💡 Hint

Consider what happens if the database guesses wrong about data distribution.