I know that ‘limit’ command is used for pagination in websites.
I wonder if DB is able to find the starting index without linearly going over the result set.
For example, for a query ‘Find something between 100th and 120th’, does DB have a way to locate the 100th item of the query without going over the 100 items linearly?
If it has to do the linear search indeed, I guess the pagination I see in any big sites is not implemented by simple ‘limit’ command?
Without talking about specific implementations, there are certainly data structures that support instantaneous lookups based on offsets. Think about normal C arrays of integers, structs and pointers (probably pointing to structs).
Beyond that relational databases have a variety of caching schemes so that even if the first lookup takes a while, subsequent queries can be sped up significantly.
In the case of actual implementations, you should always ORDER BY and LIMIT on a column that is indexed.