Create an index

Use the "alter table ~ add index" command to create an index.

alter table table name add index index name (column name);

This is a sample to create an index on author_id of book table. You can use any index name you like, but try to use a descriptive name.

alter table book add index book_author_id (author_id);

If you want to check the created index, please refer to the following article.

If you want to delete the index, please refer to the following article.

What is an index?

Indexing is a technique for improving the performance of row selection.

Index makes select dramatically faster

In the case of a linear search that searches line by line, the amount of calculation is O (n), but when an index is created, the search is performed using an algorithm called a balance tree, so the amount of calculation is O (log(n)). Become.

In general, index the fields you are searching for in a table with a large number of rows.

Creating an index makes select dramatically faster.

Disadvantages of creating an index

There is also the disadvantage of creating an index.

Creating an index increases the capacity of the database by the amount of the index.

Since the index is rebuilt at the time of insert, the perforce when inserting is slightly reduced.

Index the required fields appropriately.

Associated Information