Most query engines have a query optimizer that attempts to create an effective query execution strategy. If indexes are available that can make the query faster, then the query optimizer will scan the index or search for the index, otherwise it will scan the table.
Example:
SELECT * FROM tbl WHERE category_id = 5;
If the category_id index is missing, then the table will be scanned, that is, each individual record in the table will be checked for the correct category_name.
If, however, category_id is indexed, things become more complex. If the table is very large, index search is likely to be selected. However, if the table is small, the optimizer may decide that scanning the table is faster, because accessing the index requires some overhead. If category_id is not selective enough, for example, if there are only two categories, table scans can be faster even for large tables.
Indexes are usually organized as tree structures. Finding an item in a tree is an O (log n) operation. Scanning a table is an O (n) operation. The speed is determined mainly by the number of disk accesses required to complete the request. First, index search and subsequent table access for found records can generate more disks for small tables.
Let's look at another query:
SELECT category_id FROM tbl WHERE category_id BETWEEN 10 AND 100;
Here is another option. In this situation, index search may not be faster than table scan, but since we only retrieve catergory_id, index scan (not index search) may be even faster. An index scan reads each entry in the index table instead of using a tree structure (which makes an index search). However, since the requested information is completely contained in the index, access to the data table is not required. Scanning an index, like a table, performs O (n) operation, but since the index is usually smaller than the table, scanning the index requires less disk access than scanning the table.
The whole question is very complex and largely depends on the database engine. If you want to know more, read the documentation provided by the db provider.