Bird
0
0

A developer wrote this query for keyset pagination:

medium📝 Debug Q7 of 15
Rest API - Pagination Patterns
A developer wrote this query for keyset pagination:
SELECT * FROM messages WHERE timestamp > :last_timestamp ORDER BY timestamp DESC LIMIT 20;

What is the issue with this query?
AUsing timestamp instead of id is invalid
BOrdering DESC with > operator causes missing rows
CLIMIT 20 is too large for keyset pagination
DNo WHERE clause to filter rows
Step-by-Step Solution
Solution:
  1. Step 1: Check ordering and filter logic

    Ordering DESC means newest first, but WHERE timestamp > last_timestamp fetches newer timestamps, which conflicts.
  2. Step 2: Understand keyset pagination consistency

    For DESC order, filter should be WHERE timestamp < last_timestamp to get older rows.
  3. Final Answer:

    Ordering DESC with > operator causes missing rows -> Option B
  4. Quick Check:

    Order and filter mismatch = C [OK]
Quick Trick: Match WHERE operator direction with ORDER BY [OK]
Common Mistakes:
  • Using > with DESC order instead of <
  • Assuming timestamp can't be cursor
  • Ignoring WHERE clause importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes