An index offers an efficient way to quickly access the records from the database files stored on the disk drive. It optimizes the database querying speed by serving as an organized lookup table with pointers to the location of the requested data.
Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. This is much faster than reading every row sequentially.
MySQL uses indexes for these operations:
- To find the rows matching a
WHERE
clause quickly. - To retrieve rows from other tables when performing joins.
Ref: https://dev.mysql.com/doc/refman/8.0/en/mysql-indexes.html