You have a Supabase table with 1000 rows. You use offset pagination with limit=10 and offset=20. What rows will you get?
const { data, error } = await supabase
.from('items')
.select('*')
.range(20, 29);Remember that offset starts counting from zero, so offset 20 means skipping the first 20 rows.
Supabase's range(start, end) method includes rows from start to end inclusive, zero-based. So range(20, 29) returns rows 21 to 30.
You want to build a Supabase app that lists millions of records. Which pagination method is best to ensure fast, consistent loading?
Think about how offset pagination slows down with large offsets.
Offset pagination becomes slower as offset grows because the database must skip many rows. Cursor-based pagination uses a unique column to fetch the next set efficiently, making it better for large datasets.
You implement cursor pagination in Supabase using a timestamp column. What security risk might occur if you expose raw timestamps as cursors in URLs?
Think about what happens if users change the cursor value manually.
Exposing raw timestamps allows users to guess cursor values and potentially access data they shouldn't see. It's safer to encode cursors or use opaque tokens.
In a Supabase app, data changes frequently. Which pagination pattern helps avoid skipping or repeating rows when new rows are inserted during pagination?
Consider how new rows affect offset positions.
Offset pagination can skip or repeat rows if data changes during pagination. Cursor pagination with a stable unique column avoids this by always starting after the last seen item.
Given a Supabase table with an index on created_at, which query will perform best for paginating 10,000+ rows?
Options:
- Offset pagination:
select * from items order by created_at desc limit 10 offset 10000 - Cursor pagination:
select * from items where created_at < last_seen_created_at order by created_at desc limit 10
Think about how offset affects query execution time on large tables.
Offset pagination requires scanning and skipping many rows, which slows down as offset grows. Cursor pagination uses an indexed filter to jump directly to the next rows, improving performance.