Databases · Senior · Question 63 of 75

For WHERE tenant_id = $1 AND created_at > $2 ORDER BY created_at, which composite index order is best?

Explanation

With the equality column first, all rows for the tenant are adjacent and already sorted by time. A range column first would scatter each tenant across the index.

Further reading

Problem with a question

Databases · Senior · question 63

Test yourself

Take the Databases · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz