Subjects Questions Quizzes Pricing
Intermediate Open Pro

B-Tree vs Hash Index

You have a sessions table with a token column (UUID, unique per session) and a user_id column. Your application runs two types of queries:

  1. SELECT * FROM sessions WHERE token = $1 (exact lookup, high frequency)
  2. SELECT * FROM sessions WHERE user_id = $1 ORDER BY created_at DESC LIMIT 10 (range + sort)

Which index type would you choose for each column, and why?

← Back to Database Indexing practice