Databases · Middle · Question 71 of 75

Why can ORDER BY created_at DESC LIMIT 10 be very fast on a huge table?

Explanation

Without a suitable index the database must read and sort everything, then return 10 rows. Add the filter columns first in the index when there's a WHERE.

Further reading

Problem with a question

Databases · Middle · question 71

Test yourself

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

Take this quiz